判断功能
boolean exists():判断file对象是否存在
boolean isFile():判断file对象是否是文件
boolean isDirectory():判断file对象是否是文件夹
boolean isAbsolute():判断file对象是否是绝对路径
boolean canRead():判断file对象是否可读
boolean canWrite():判断file对象是否可写
boolean isHidden():判断file对象是否隐藏
public class FileDemo {
public static void main(String[] args) {
File file = new File("a.txt");
System.out.println("exists:" + file.exists());// true
System.out.println("isFile:" + file.isFile());// true
System.out.println("isDirectory:" + file.isDirectory());// false
System.out.println("isAbsolute:" + file.isAbsolute());// false
System.out.println("canRead:" + file.canRead());// true
System.out.println("canWrite:" + file.canWrite());// true
System.out.println("isHidden:" + file.isHidden());// false
}
} |
|