package com.thursday.demo32;
import java.io.File;
import java.util.Scanner;
public class HomeWork01 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String st = sc.nextLine();
File file1 = new File(st);
delete(file1);
}
public static void delete(File file) {
if (file.isFile()) {
file.delete();
} else if (file.isDirectory()) {
File[] file2 = file.listFiles();
if (file2.length == 0) {
file.delete();
} else {
for (File f : file2) {
delete(f);
}
}
}
file.delete();
}
}
递归删除指定文件夹的内容
最新推荐文章于 2024-03-16 18:16:43 发布