public static void main(String[] args) throws IOException {
String path = "D:\\io1\\io2\\File.txt";
File file1 = new File(path);
boolean exist = file1.exists();
/*
public static void mkdirs(String path) {
File dir = new File(path);
if(dir.getParent() == null) {
dir.mkdir();//已经到达根目录
return;
}
File dirParent = dir.getParentFile();//获取父类文件夹
if(dirParent.exists()) {
dir.mkdir();
} else {
mkdirs(dirParent.getPath());
}
dir.mkdir();
}
*/
File2.mkdirs(path);//创造文件目录
File file2 = file1.getParentFile();//获取父类文件夹
String fileName = "hello.txt";
File file3 = new File(file2, fileName);
file3.createNewFile();
if(!exist) {
if(file1.delete()) {
System.out.println("删除成功!");
}else {
System.out.println("删除失败!");
}
}
}