java删除文件包含子文件

共计 678 个字符,预计需要花费 2 分钟才能阅读完成。

// 文件删除测试



import java.io.*;



public class Delete {



 public static void main(String[] args) throws IOException {

  

  Delete.delete("F:b");



  System.out.println("ok");

 }



 

 

 // 文件名或者文件删除(可以删除包含的子文件和文件夹)

 public static boolean delete(String s) throws IOException {

  File file = new File(s);

  if(!file.delete()) {

   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;



}

正文完
 
zhaopeng
版权声明:本站原创文章,由 zhaopeng 2008-11-01发表,共计678字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)