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 33 34 35
| int BUFFER = 2048;
byte data[] = new byte[BUFFER];
try
{
FileOutputStream dest = new FileOutputStream("archive.zip");
CheckedOutputStream checksum = new CheckedOutputStream(dest, new Adler32());
BufferedOutputStream buff = new BufferedOutputStream(checksum);
ZipOutputStream out = new ZipOutputStream(buff);
out.setMethod(ZipOutputStream.DEFLATED);
out.setLevel(Deflater.BEST_COMPRESSION);
File f = new File("C:\\A\\");
String files[] = f.list();
for (int i=0; i<files.length; i++)
{
System.out.println("Adding: "+"C:\\A\\"+files[i]);
FileInputStream fi = new FileInputStream("C:\\A\\"+files[i]);
BufferedInputStream buffi = new BufferedInputStream(fi, BUFFER);
ZipEntry entry = new ZipEntry(unAccent("C:\\A\\"+files[i]));
out.putNextEntry(entry);
int count;
while((count = buffi.read(data, 0, BUFFER)) != -1)
{
out.write(data, 0, count);
}
out.closeEntry();
buffi.close();
}
out.close();
buff.close();
checksum.close();
dest.close();
System.out.println("checksum: " + checksum.getChecksum().getValue());
} catch(Exception e) {e.printStackTrace();} |