0

I am currently creating a program, that creates a Zip file of stuff.

Now, I would like to add some automatically generated "info.txt" file containing info about the Zip.

Now, I would probably just generate it as a String and would like to put it in the Zip.

Unfortunately, I have not found any way of doing this, so I would really appreciate some help.

Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175

1 Answers1

1

Trivial. When you say, "I am making a zip file of stuff", I assume you're using ZipOutputStream, but if not, you should update your question.

Path tgt = Paths.get("target.zip");
String info = "Hello, World!";
try (OutputStream out = Files.newOutputStream(tgt)) {
    ZipOutputStream zip = new ZipOutputStream(out);
    zip.putNextEntry(new ZipEntry("info.txt"));
    zip.write(info.getBytes(StandardCharsets.UTF_8));

    // write the other files here
}
rzwitserloot
  • 65,603
  • 5
  • 38
  • 52