• Post Reply Bookmark Topic Watch Topic
  • New Topic

Appending Content to a file Inside a zip file  RSS feed

 
Karan Chandra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
My requirement is to append the data to a file inside a zip file.Is it possible to directly create a file inside a zip file, then appending the content to that file.

I am trying to do it with ZipOutputStream using following class ... but itz writing content to file, but not appending to the file......
How can i append the content to the file inside a zip file.

Thanks for your help....
my class follows

import java.util.zip.*;
import java.io.*;

public class WriteIntoZip {

public static void main(String[] args) {
String str = "Hi Every One !!";
(new WriteIntoZip()).write("c:\\test.zip", "xyz.txt", str);
}

public void write(String pvZipFile, String pvEntryFile, String str) {
try {
byte[] lvByte = new byte[2048];

FileOutputStream fos = new FileOutputStream(pvZipFile);
ZipOutputStream lvZipOut = new ZipOutputStream(
new BufferedOutputStream(fos));
ZipEntry lvEntry = new ZipEntry(pvEntryFile);

lvZipOut.putNextEntry(lvEntry);

for (int i = 0; i < str.length(); i++) {
lvByte[i] = (byte) str.charAt(i);
}

lvZipOut.write(lvByte, 0, str.length());

lvZipOut.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}

}

Thanks & Regards,
Prasad
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked in to the APIs for you but I am affraid it looks like it is not possible to do something like this. You can add files to a Zip file but I don 't think it is possible to append to a single file. Sorry...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!