删除本地文件

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();
}
原文地址:https://www.cnblogs.com/IceBlueBrother/p/8422977.html