gpt4 book ai didi

Java:取消标记文件是只读的

转载 作者:可可西里 更新时间:2023-11-01 12:42:43 26 4
gpt4 key购买 nike

我可以在 Java 上执行此操作吗?我正在使用 Windows...

最佳答案

http://java.sun.com/j2se/1.6.0/docs/api/java/io/File.html#setReadOnly%28%29

File file = new File("foo.bar");
if(file.setReadOnly()) {
System.out.println("Successful");
}
else {
System.out.println("All aboard the fail train.");
}

在 Java6 之前,您无法撤消此操作。为了解决这个问题,他们放入了可以这样使用的 File.setWritable(boolean)

File file = new File("foo.bar");
if(file.setWritable(false)) {
System.out.println("Successful");
}
else {
System.out.println("All aboard the fail train.");
}

if(file.setWritable(true)) {
System.out.println("Re-enabled writing");
}
else {
System.out.println("Failed to re-enable writing on file.");
}

关于Java:取消标记文件是只读的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2877106/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com