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.

[1490 byte] By [KapilGhodawata] at [2007-11-27 9:31:58]
# 1

hi

i want to sugest you like:--

say fileoutputstreem.flesh();

call this flesh() method . It is just like commit in DB.

Through this U may salve your problem.

You are creating zip files like a.zip and b.zip if you save in your c:\\ it will take some IO Operations. It is not sugested.

If you want to like that only i will sujest you to delete them after your process is completed.

krosurua at 2007-7-12 22:48:16 > top of Java-index,Java Essentials,Java Programming...
# 2
Hi,Thanx for the suggestion. Actually I found the problem with my code. I need to use GZip format instead of ZIP.Using that solves my problem..Anyways thanx for all the help :)
KapilGhodawata at 2007-7-12 22:48:16 > top of Java-index,Java Essentials,Java Programming...