public class Test {
public static void main(String[] args)throws Exception{
//random(5, 100);
File file = new File("D:\\test");
deleteFile(file);
}
public static void deleteFile(File file) {
if(!file.exists()){
System.out.println("文件夹路径不存在");
}else{
File[] files = file.listFiles();
for (File file2 : files) {
if(file2.isFile()){
file2.delete();
}
else{
deleteFile(file2);
}
}
file.delete();
}
}
public static void random(int n, int L){
Random rand = new Random();
int temp = L;
for(int i = 0, j; i < n-1; i++){
j = rand.nextInt(temp-1) + 1;
temp -= j;
System.out.println(j);
}
System.out.println(temp);
}
} |