检查其他用户是否具有写入文件的权限 [英] Check if another user have the permission to write a File

查看:201
本文介绍了检查其他用户是否具有写入文件的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安装过程中,我需要检查用户提供的路径是否可写入指定用户。

During an installation process I need to check if a userprovided path is writable to a specified user.

路径(UNC路径,如\ fileserver \ share) )可能无法写入正在执行Setup.exe的用户(这是一个仅限Windows的软件),所以我认为如何检查写入目录或文件的权限?可能对我不起作用。

The Path (A UNC Path like \fileserver\share) may not be writable to the user, who is executing the Setup.exe (It's a Windows-Only Software), so I think How do you check for permissions to write to a directory or file? may not work for me.

我知道在Java7中会有一个新的Filesystem-API,但Java7还没有发布。

I know in Java7 there will be a new Filesystem-API, but Java7 is not released yet.

编辑:
用户1 - 运行安装程序
用户2 - 运行已安装的应用程序

User 1 - runs the installer User 2 - runs the installed application

如果用户1收到错误权限被拒绝我仍然不知道,关于用户2.我需要在安装过程中检查其他useccount的许可。

If user 1 get an error "Permission denied" I still don't know, about user 2. I need to check the permission for an other useraccount during the process of installation.

我可以使用 net use / user:< user2> < passwd2> 但是我不确定,如果我得到了我需要的所有信息。我得到的信息是路径存在,但不是,如果允许用户2写。

I may use net use /user:<user2> <passwd2> but I'm not sure, if I get all information I need. I get the information, that the path exists, but not, if User 2 is allowed to write.

推荐答案

在java 7之前,您没有标准方法来检查用户是否可以使用标准库写入java文件。这是因为旧的java io不够强大。

before java 7, you don't have standard way to check if a user can write to a java file using standard library. this is because the old java io just is not power enough.

例如,如果考虑文件所有者等,File.canWrite()将无效....

for example, File.canWrite() will not work if consider file owner, etc....

你可以做的是直接检查,例如,尝试写一个空行。 (这需要考虑你的应用程序,如果你的应用程序只是不在乎最后一行并自动删除结束空行,那么它的工作原理.....这只是一个例子,你可以采取许多棘手的方法考虑你的应用。

what you can do is check it in directly, for example, try to write a empty line to it. (this need to consider you application,if your application just don't care a blank line at end and auto delete ending blank lines , then it works..... this is just an example, you can get many tricky ways considering your applicaton.

这篇关于检查其他用户是否具有写入文件的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆