结伴

java删除文件包含子文件

//文件删除测试import java.io.*;public class Delete {&nbsp;public static void main(String[] args) throws IOException {&nbsp;&nbsp;&nbsp;&nbsp;Delete.delete("F:b");&nbsp;&nbsp;System.out.println("ok");&nbsp;}&nbsp;&nbsp;&nbsp;//文件名或者文件删除(可以删除包含的子文件和文件夹)&nbsp;public static boolean delete(String s) throws IOException {&nbsp;&nbsp;File file = new File(s);&nbsp;&nbsp;if(!file.delete()) {&nbsp;&nbsp;&nbsp;String[] f = file.list();//列出当前文件夹中的所以文件包括文件夹&nbsp;&nbsp;&nbsp;for(int i = 0; i < f.length; i++) {&nbsp;&nbsp;&nbsp;&nbsp;delete(file.getAbsolutePath() + "" + f[i]);//对子文件夹进行处理&nbsp;&nbsp;&nbsp;&nbsp;return &nbsp;delete(file.getAbsolutePath());//返回上级目录&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;}&nbsp;&nbsp;return true;&nbsp;}&nbsp;}