package com.hui_kehou1;
import java.io.File;
public class Delet {
public static void main(String[] args) {
String s = "F:\\delete";
File file = new File(s, "day14");
System.out.println("文件存在?"+file.exists());
if(file.exists()){
System.out.println("查看文件是否为空的");
File[] listFiles = file.listFiles();
for (File file2 : listFiles) {
System.out.println(file2);
}
delete_f(file);
System.out.println("文件是否删除?"+!file.exists());
}else{
System.out.println("没有此文件");
}
}
private static void delete_f(File file) {
// TODO Auto-generated method stub
File[] listFiles = file.listFiles();
for (File file2 : listFiles) {
if (file2.isFile()) {
file2.delete();
} else {
delete_f(file2);
}
}
file.delete();
}
}
|
|