java删除文件中第二个a_如何在Java中删除包含其他文件夹的文件夹?

参见英文答案 >

Delete directories recursively in Java                                    23个

这是我试过的代码:

import java.io.*;

public class file03 {

public static void main(String[] args) {

File f1 = new File("C:/tempo1/tempo");

f1.mkdirs();

File f2 = new File("C:/test");

if(!f2.exists()) {

f2.mkdir();

}

f1 = new File("C:/tempo1/kempo");

f1.mkdirs();

f1 = new File("C:/tempo1");

String[] t = {};

if(f1.exists()) {

t = f1.list();

System.out.println(t.length + " files found");

}

for(int i = 0; i < t.length; i++) {

System.out.println(t[i]);

}

try {

Thread.sleep(3000);

}

catch(Exception e) {}

f2.delete();

f2 = new File("C:/tempo1/test.txt");

try {

f2.createNewFile();

}

catch(Exception e) {}

try {

Thread.sleep(7000);

}

catch(Exception e) {}

File f3 = new File("C:/tempo1/renametesting.txt");

f2.renameTo(f3);

try {

Thread.sleep(5000);

}

catch(Exception e) {}

f3 = new File("C:/tempo1");

f3.delete();

}

}

我注意到的是,当文件夹测试被删除时,文件夹tempo1不会被删除.是因为它包含其他文件夹和文件吗?如果是这样,我该如何删除它?

我正在使用BlueJ IDE.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值