public class day21deleteFile {
public static void main(String agrs[]) {
Scanner sc = new Scanner(System.in);
System.out.println("please enter a file path");
File file = new File(sc.nextLine());
boolean flag = deleteFile(file);
System.out.println("flag=" + flag);
}
public static boolean deleteFile(File file) {
boolean flag = false;
System.out.println(file.getName() + "is File" + file.isFile()
+ " is directory" + file.isDirectory());
if (file.isFile()) {
flag = file.delete();
} else if (file.isDirectory()) {
for (File file1 : file.listFiles()) {
flag = deleteFile(file1);
}
file.deleteOnExit();
} else {
System.out.println("this is not a file");
}
return flag;
}
} 作者: 魏志林 时间: 2016-1-2 10:08
怎么把文件夹删除的,没看明白作者: 337325635 时间: 2016-1-2 21:52
还没学了 进来看一下