You have to call
Below sample code(Don't treat it as good code)
close()
on the GZIPOutputStream
before you attempt to read it. The final bytes of the file will only be written when the file is actually closed. (This is irrespective of any explicit buffering in the output stack. The stream only knows to compress and write the last bytes when you tell it to close. A flush()
probably won't help ... though calling finish()
instead of close()
should work. Look at the javadocs.)Below sample code(Don't treat it as good code)
String name = "/tmp/test";
GZIPOutputStream gz = new GZIPOutputStream(new FileOutputStream(name));
gz.write(10);
gz.close();
System.out.println(new GZIPInputStream(new FileInputStream(name)).read());
Comments
Post a Comment