Java Java File.isFile()
方法具有以下語法。
public boolean isFile()
在下面的程式碼顯示如何使用File.isFile()
方法。
import java.io.File;
public class Main {
public static void main(String[] args) {
File f = new File("c:");
// true if the file path is a file, else false
boolean bool = f.isFile();
// get the path
String path = f.getPath();
System.out.println(path + " is file? " + bool);
// create new file
f = new File("c:/test.txt");
// true if the file path is a file, else false
bool = f.isFile();// from:w w W .Y ii B A I.C O m
// get the path
path = f.getPath();
System.out.print(path + " is file? " + bool);
}
}
執行上面程式碼,得到以下結果 -
c: is directory? true
c:\test.txt is directory? false