删除本地文件

File file = new File("C:/zc.xls");
if (file.isFile() && file.exists()) {
  file.delete();
}

 

如果文件下面有东西的话,要一层层的删

public void delTempChild(File file){
if (file.isDirectory()) {
      String[] children = file.list();//获取文件夹下所有子文件夹
    //递归删除目录中的子目录下
      for (int i=0; i<children.length; i++) {
      delTempChild(new File(file, children[i])); 
      }
  }
  // 目录空了,进行删除
  file.delete();
}
posted @ 2018-02-06 16:31  Ice_Blue_Brother  阅读(389)  评论(0编辑  收藏  举报