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

该代码片段展示了如何在Linux系统中检查文件的读写执行权限。然而,在Windows7上运行时遇到问题。问题在于如何在Java中实现独立于操作系统的文件权限检查。解决方案可能涉及使用Java的Files类和PosixFileAttributes接口,这些在不同操作系统下有不同的行为。
摘要由CSDN通过智能技术生成

我有以下代码片段:

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!!!!!");

}

}它适用于Linux操作系统,但问题在于它不适用于Windows7。所以问题是:有没有人知道一种方法来独立检查Java OS中的文件权限?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值