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