In this tutorial you will see how to Compress file using DeflaterOutputStram class in java.
In this tutorial you will see how to Compress file using DeflaterOutputStram class in java.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:
Return Type | Method | Description |
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. |
import java.io.*;
dflOutStream.finish(); dflOutStream.close();
|
C:\>java DeflOutStream Fill data SuccessFully Compressed at Level : 4 |