1.File类
1.创建File对象
File类提供了专门创建File对象的构造方法,具体如下
2.File类的常用方法
File类提供了一系列方法,用于操作器内部封装的路径指向的文件或者目录。常见方法如下
方法演示
import java.io.*;
class EXample{
public static void main(String[] args)throws IOException{
//磁盘下创建文件
File file=new File("d:\\hello\\demo.txt");
//如果存在这个文件就删除,否则就创建
if(file.exists()){
file.delete();
}else{
System.out.println(file.createNewFile());
}
//在磁盘下创建一层目录,并且在目录下创建文件
File fileDemo=new File("d:\\hello1\\demo.txt");
//判断d:\\hello1 目录是否存在
if(!(fileDemo.getParentF