In this tutorial, we will discuss how to use DeflaterOutputStream class in
java. The DeflaterOutputStream class creates an output Stream for
compressing data with an associated deflater. The DeflaterOutputStream
class is available in java.util.zip package. The write(int b) method
of DeflaterOutputStream class write one byte on associated stream.
In this Example, we will compressed the data of a file by using DeflaterOutputStream class. The DeflaterOutputStream(OutStream out, Deflater defl) constructor DeflaterOutputStream class create an output stream with a specific compressor. The Defleter class create a compressor for compressing data. The FileInputStream class creates a input stream for reading data from a file. The setLevel() method of Deflater class is used to set level of data compression. The read() method of FileInputStream class read data from input stream.
About DeflaterOutputStream API:
The java.util.zip.DeflaterOutputStream class extends java.io.FilterIntputStream class. It provides the following methods:
|int||write(int b)||The write( int b) method write one byte on associated output stream|
|void||close()||The close() method close underlaying output stream after writing compressed data.|
|void||finish()||The finish() method finish writing compressed data on associated stream without closing stream.|
Fill data SuccessFully Compressed at Level : 4
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.