Java压缩大文件 [英] Java Compress Large File
问题描述
我正在开发的工作与一些非常大的文件,每个大约180mb,有3个应用程序。我想添加一个选项到我的应用程序来回复这些文件通过压缩它们在一个zip或tar或某物。什么是最好的选择是在Java中尽可能多地压缩它们?柏油?压缩? Gzip?
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?
推荐答案
这里使用zip就是我使用的方法。我发现它在线,并修改它垃圾的路径,然后只是提高缓冲区一点有约450mbs的数据下降到100mbs所以没有坏:)感谢帮助
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) {
}
}
$ b b
加1给你们两人:)
Plus 1 to both of you :)
这篇关于Java压缩大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!