Java Java File.setReadOnly()
方法具有以下语法。
public boolean setReadOnly()
示例
在下面的代码显示如何使用File.setReadOnly()
方法。
import java.io.File;
public class Main {
public static void main(String[] args) {
File f = new File("test.txt");
// set file as read only
boolean bool = f.setReadOnly();
System.out.println("setReadonly() succeeded?: " + bool);
// checks whether the file is writable
bool = f.canWrite();
System.out.print("Is file writable?: " + bool);
}
}
上面的代码生成以下结果。
setReadonly() succeeded?: true
Is file writable?: false