1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
private void save(String zipName) {
try {
ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(ZIP_FILE));
zip.setMethod(ZipOutputStream.DEFLATED);
zip.setLevel(Deflater.BEST_COMPRESSION);
File dataFile = new File(zipName);
addFile(dataFile, zip);
zip.close();
}
catch (FileNotFoundException fileNotFound) {}
catch (IOException io) {}
}
private void addFile(File file, ZipOutputStream zip) {
try {
FileInputStream in = new FileInputStream(file);
byte[] bytes = new byte[in.available()];
in.read(bytes);
in.close();
ZipEntry entry = new ZipEntry(file.getName());
entry.setTime(file.lastModified());
zip.putNextEntry(entry);
zip.write(bytes);
zip.closeEntry();
}
catch (FileNotFoundException fileNotFound) {new FenetreException(fileNotFound,true);}
catch (IOException io) {new FenetreException(io,true);}
} |
Partager