File
1.概述:
Java文件类以抽象的方式代表文件名和目录路径名。该类主要用于文件和目录的创建、文件的查找和文件的删除等,File对象通常可以代表磁盘中实际存在的文件和目录。
2.常用方法
1>构造方法
new File(File parent, String child) //根据 parent 抽象路径名和 child 路径名字符串创建一个新 File 实例。
new File(String pathname) //通过将给定路径名字符串转换为抽象路径名来创建一个新 File 实例。
new File(String parent, String child) //根据 parent 路径名字符串和 child 路径名字符串创建一个新 File 实例。
new File(URI uri) //通过将给定的 file: URI 转换为一个抽象路径名来创建一个新的 File 实例。
2>常用方法
boolean exists():是否存在
String getAbsolutePath():绝对路径
String getName():文件名
int length():文件大小
String getParent():父目录路径
File getParentFile():父目录file对象
boolean isDirectory() 测试此抽象路径名表示的文件是否是一个目录。
boolan isFile() 测试此抽象路径名表示的文件是否是一个标准文件。
File的增删改查
1.创建文件
//构建路径
String pathname = "d:" + File.separator + "a&