Java删除文件和删除文件

private void deleteFiles(List<String> fileList, String path){

  for (int index = 0; index < fileList.size(); index++) {

  String fullName = path + fileList.get(index);

  File file = new File(fullName);

  if (file.isFile() && file.exists()) {

  file.delete();

  }

  }

  }

  private void zipFile(List<String> fileList, String path, String zipFN) throws IOException {

  FileOutputStream fileOut = new FileOutputStream(path + zipFN);

  ZipOutputStream outputStream = new ZipOutputStream(fileOut);

  for (int index = 0; index < fileList.size(); index++) {

  String fileName = fileList.get(index);

  String fullName = path + fileName;

  FileInputStream fileIn = new FileInputStream(fullName);

  ZipEntry entry = new ZipEntry(fileName);

  outputStream.putNextEntry(entry);

  byte[] buffer = new byte[1024];

  while (fileIn.read(buffer) != -1) {

  outputStream.write(buffer);

  }

  outputStream.closeEntry();

  fileIn.close();

  }

  outputStream.close();

  fileOut.close();

}

评论

暂无评论