Compressed Java File

I am working on an application that works with very large files, each of which is about 180 mb, and there are 3 of them. I would like to add an option to my application to return these files by compressing them to zip or tar or something like that kind. What is the best option - compress them as much as possible in Java? Tar? Zip? Gzip?

+2
source share
3 answers

Good thing I used zip, this is the method I used. I found it online and modified it to disrupt the path, and then just raised the buffer, received a little about 450 MB of data up to 100 MB so that it wasn’t 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 :)

+1
source
+5

Look at the classes in the java.util.zip package .

+2
source

All Articles