Zip: concatening compressed chunks, will it give a single zip file
Are concatenated zipped chunks recognized as a single zip file?
What I am trying to achieve(using java.util.zip) is like, my application is generating a large CSV file, i need to compress this data and write it into a file or send to network. But I dont want to wait until the complete data generation and need to compress data in chunks; assuming that if i append my compressed chunks to a file at last i will get a valid & complete zip file.
For testing this I made a sample program like:
//Here a.zip b.zip are files compressed using java.util.zip; here they act as
// data chunk (actually these will be genarted by my
// application dynamically & in parallel to this process)
FileInputStream f1 = new FileInputStream(new File("c://a.zip"));
FileInputStream f2 = new FileInputStream(new File("c://b.zip"));
// Opening file in append mode
FileOutputStream fos = new FileOutputStream("c://c.zip",true);
byte[] data = new byte[(int)new File("c://a.zip").length()];
f1.read(data);
fos.write(data);
byte[] data2 = new byte[(int)new File("c://b.zip").length()];
f2.read(data2);
fos.write(data2);
f1.close();
f2.close();
fos.close();
But this program does not work, as m not getting the final zip file containing the whole data, rather it gives data only from first file.
Can any one point out the error.
Or suggest me the better way to achieve this.

