Search code examples
javatruezip

How to create zip file using TrueZip?


The example on their website is

File entry = new TFile("archive.zip/dir/HälloWörld.txt");
Writer writer = new TFileWriter(entry);
try {
    writer.write("Hello world!\n");
} finally {
    writer.close();
}

In my use case, I have the following structure

log/a.log
log/b.log
log/morelog/1.log
c.log
d.log

I want to zip all of them. As per example, they create entry and write data into it.

Question
- if I need to copy the data from eachfile like this, this would be inefficient, right?

How can I just give filepaths and tell it to create zip?


Solution

  • For copying, have a look at TFile.cp_rp(File).