Java Java File.setReadable(boolean readable)
方法具有以下語法。
public boolean setReadable(boolean readable)
在下面的程式碼顯示如何使用File.setReadable(boolean readable)
方法。
import java.io.File;
public class Main {
public static void main(String[] args) {
File f = new File("test.txt");
// set read permission // from: WW W .yII bA i .C o m
boolean bool = f.setReadable(true);
System.out.println("setReadable() succeeded?: " + bool);
// checks whether the file is readable
bool = f.canRead();
System.out.print("Is file readable?: " + bool);
}
}
上面的程式碼生成以下結果。
setReadable() succeeded?: true
Is file readable?: true