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
  • 100,966
  • 191
  • 140
  • 197

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
  • 85,357
  • 5
  • 51
  • 72