Java删除文件和删除文件
发布时间:2010/9/21 11:18:49 来源:城市学习网 编辑:ziteng
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);// "StockValuation.xls";
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();
}