我正在尝试设置文件的只读属性,但它似乎不起作用。有人可以帮我理解为什么吗?
这是我的代码...
public class Main {
public static void main(String[] args) {
File f = new File("c:/ulala.txt");
if (!f.setReadOnly()) {
System.out.println("Grrr! Can't set file read-only.");
return;
}
}
}
最佳答案
该文件必须存在并且用户必须有权更改该文件的权限。您可以使用 f.exists()
测试文件是否存在。
关于java - 设置文件的只读属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10207317/