0

With the use of createZipReport, I am adding list of files and folders to be zipped up. The createZipReport then calls the zipFileList to zip up the whole folder.

The question is I need to zip a folder inside this already existing folder without changing much.

For example

Directory.zip

  Files
  SubFolder1
  SubFolder2

The files, subFolder1 and subFolder2 are added with the help of fileList in createZipReport

Now I need the subFolder1 to be a zip folder i.e.SubFolder1.zip

Any suggestions?

Shiney
  • 1
  • 1
  • The only solution I can see for this is to extract `SubFolder1`, zip this folder to a zip file, add this zip to the existing zip (`Directory.zip` in your case), and then delete folder `SubFolder1` from your `Directory.zip` file. – Srikanth Reddy Lingala Jun 06 '22 at 14:14

1 Answers1

0

You can create new or use existed zip file to add new files and folers with zip4jvm

Path zip = Paths.get("filename.zip");
Collection<Path> paths = Arrays.asList(
        Paths.get("/bikes/ducati-panigale-1199.jpg"),
        Paths.get("/bikes/honda-cbr600rr.jpg"),
        Paths.get("/cars"),
        Paths.get("/saint-petersburg.jpg"));
ZipIt.zip(zip).add(paths);

When you do it multiple times, your existed zip file will not be corrupted and all entires will be there.

Oleg Cherednik
  • 17,377
  • 4
  • 21
  • 35