I'm working on an app that works with some very large files each are around 180mb and there are 3 of them. I would like to add an option to my app to back these files up by compressing them in a zip or a tar or something. What is the best option would be to compress them down as much as possible in Java? Tar? Zip? Gzip?
Asked
Active
Viewed 8,584 times
2
-
1Alright so you both suggest i use zip then for the most compression? – user577732 Jul 01 '11 at 00:49
-
1If you know the format or contents of the file, maybe a customized compressor works better than a generic one. Also make sure the files only have the absolute important data you want to be backed up. – Luciano Jul 01 '11 at 02:40
2 Answers
5
You can do this programmatically using Apache Compress.

Perception
- 79,279
- 19
- 185
- 195
-
1Yup. Depends on the tradeoff you want between complexity and performance. Java has ZIP support as part of the standard library (see other comment), but you will get MUCH better compression using bzip, or tar.gz. Apache Compress is the easiest way to work with those formats, if you're willing to accept the extra JAR dependencies. – Steve Perkins Jul 01 '11 at 00:09
1
Alright went with zip here is the method i used. I found it online and modded it to junk the path and then just raised the buffer a little got about 450mbs of data down to 100mbs so not to bad :) thanks for the help
public void zipper(String[] filenames, String zipfile){
byte[] buf = new byte[2048];
try {
String outFilename = zipfile;
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
for (int i=0; i<filenames.length; i++) {
FileInputStream in = new FileInputStream(filenames[i]);
File file = new File(filenames[i]);
out.putNextEntry(new ZipEntry(file.getName()));
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
in.close();
}
out.close();
} catch (IOException e) {
}
}
Plus 1 to both of you :)

user577732
- 3,956
- 11
- 55
- 76