Java File.canRead()
方法具有以下語法。
public boolean canRead()
在下面的程式碼顯示如何使用File.canRead()
方法。
import java.io.File;
public class Main {
public static void main(String[] args) {
File f = new File("c:/test.txt");
// returns true if the file can be read
boolean bool = f.canRead();// @ w Ww . y iI b AI.c O M
System.out.print("File can be read: " + bool);
}
}
上面程式碼執行結果如下 -
File can be read: false