posted 7 years ago
Hi, Anka
My suggestion is that your are closing file output stream before deflater output stream. Deflater have an internal buffer and process data in "batches" by compressing them. It ocasionally write data and also finishes compression and flushes the buffer when close() method is called. However, file stream is closed one line above so all the remaining data are lost and the resulting file is "truncated". Switching an order should help. Or even better, you do not have to close the file stream by hand. DeflaterOutputStream will close the underlying stream when dos.close() is called.
BTW, do you get any exceptions running your program? An exception should happen in line 17, where DeflaterOutputStream tries to write into the already-closed file stream. So the code should say "Exception in Compress/Decompress program".