import java.io.File;
import java.io.IOException;
public class helloworld {
public static void main(String[] args) throws IOException{
File file = new File("d:\\test\\hyx");//文件对象指代文件夹
if(file.exists()){
System.out.println("1");
} /*所以说执行上面那个语句之后文件夹是不存在的,所以继续执行下面的语句才能使文件创建成功,下面删除和另一种创建同此*/
boolean b = file.mkdirs();///深度创建文件夹
System.out.println(b); //创建成功则返回true,否则返回false
File file1 = new File(file,"test.txt");
b = file1.createNewFile();
System.out.println(b); //创建成功则返回true,否则返回false
File file2 = new File("d:\\test\\hyx\\hh.txt"); ///在已有的文件夹下创建
if(file2.exists()){
System.out.println("文件已经存在");
}
else{
boolean bo = file2.createNewFile();
System.out.println("文件已经创建成功");
}
File file3 = new File("d:\\test\\hyx\\hhy.txt"); ///在已有的文件夹下创建
if(file3.exists()){
file3.delete();
System.out.println("文件已删除");
}
else{
System.out.println("文件不存在");
}
}
}