小编Jar*_*bek的帖子

如何在Java中检查文件权限(OS独立)

我有以下代码片段:

public class ExampleClass {

public static void main(String[] args) throws FileNotFoundException {
    String filePath = args[0];
    File file = new File(filePath);

    if (!file.exists())
        throw new FileNotFoundException();

    if (file.canWrite())
        System.out.println(file.getAbsolutePath() + ": CAN WRITE!!!");
    else
        System.out.println(file.getAbsolutePath() + ": CANNOT WRITE!!!!!");

    if (file.canRead())
        System.out.println(file.getAbsolutePath() + ": CAN READ!!!");
    else
        System.out.println(file.getAbsolutePath() + ": CANNOT READ!!!!!");

    if (file.canExecute())
        System.out.println(file.getAbsolutePath() + ": CAN EXECUTE!!!");
    else
        System.out.println(file.getAbsolutePath() + ": CANNOT EXECUTE!!!!!");
}
}
Run Code Online (Sandbox Code Playgroud)

它适用于Linux操作系统,但问题是它在windows7中不起作用.所以问题是:是否有人知道在Java OS中独立检查文件权限的方法?

java file-permissions

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

file-permissions ×1

java ×1