Java.util.zip.DeflaterOutputStream class in Java Last Updated : 12 Sep, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Java.util.zip.DeflaterInputStream class in Java This class implements an output stream filter for compressing data in the "deflate" compression format. It is also used as the basis for other types of compression filters, such as GZIPOutputStream. Constructors and Description DeflaterOutputStream(OutputStream out) : Creates a new output stream with a default compressor and buffer size. DeflaterOutputStream(OutputStream out, boolean syncFlush) : Creates a new output stream with a default compressor, a default buffer size and the specified flush mode. DeflaterOutputStream(OutputStream out, Deflater def) : Creates a new output stream with the specified compressor and a default buffer size. DeflaterOutputStream(OutputStream out, Deflater def, boolean syncFlush) : Creates a new output stream with the specified compressor, flush mode and a default buffer size. DeflaterOutputStream(OutputStream out, Deflater def, int size) : Creates a new output stream with the specified compressor and buffer size. DeflaterOutputStream(OutputStream out, Deflater def, int size, boolean syncFlush) : Creates a new output stream with the specified compressor, buffer size and flush mode. Methods: void close() : Writes remaining compressed data to the output stream and closes the underlying stream. Syntax :public void close() throws IOException Overrides: close in class FilterOutputStream Throws: IOException protected void deflate() : Writes next block of compressed data to the output stream. Syntax :protected void deflate() throws IOException Throws: IOException void finish() : Finishes writing compressed data to the output stream without closing the underlying stream. Syntax :public void finish() throws IOException Throws: IOException void flush() :Flushes the compressed output stream. Syntax :public void flush() throws IOException Overrides: flush in class FilterOutputStream Throws: IOException void write(byte[] b, int off, int len) : Writes an array of bytes to the compressed output stream. Syntax :public void write(byte[] b, int off, int len) throws IOException Overrides: write in class FilterOutputStream Parameters: b - the data to be written off - the start offset of the data len - the length of the data Throws: IOException void write(int b) : Writes a byte to the compressed output stream. Syntax :public void write(int b) throws IOException Overrides: write in class FilterOutputStream Parameters: b - the byte to be written Throws: IOException Java //Java program to demonstrate DeflaterOutputStream import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.DeflaterOutputStream; class DeflaterOutputStreamDemo { public static void main(String[] args) throws IOException { FileOutputStream fos = new FileOutputStream("file2.txt"); //Assign FileOutputStream to DeflaterOutputStream DeflaterOutputStream dos = new DeflaterOutputStream(fos); //write it into DeflaterOutputStream for (int i = 0; i <10 ; i++) { dos.write(i); } //illustrating flush() method() dos.flush(); //illustrating finish() //Finishes writing compressed data to the output stream // without closing the underlying stream dos.finish(); //fos is not closed //writing some data on file fos.write('G'); //Writes remaining compressed data to the output stream // closes the underlying stream. dos.close(); } } Note: Output of the program will not be visible on online IDE as file2.txt can not be read here. Comment More infoAdvertise with us Next Article Java.util.zip.DeflaterInputStream class in Java C ChippingEye2766 Improve Article Tags : Advance Java Similar Reads Java.io.ObjectOutputStream Class in Java | Set 2 Java.io.ObjectOutputStream Class in Java | Set 1 More Methods: void write(byte[] buf) : Writes an array of bytes. This method will block until the byte is actually written. Syntax :public void write(byte[] buf) throws IOException Parameters: buf - the data to be written Throws: IOException void writ 8 min read Java.util.zip.DeflaterInputStream class in Java Implements an input stream filter for compressing data in the "deflate" compression format. Constructor and Description DeflaterInputStream(InputStream in) : Creates a new input stream with a default compressor and buffer size. DeflaterInputStream(InputStream in, Deflater defl) : Creates a new input 3 min read Java.util.zip.ZipOutputStream class in Java This class implements an output stream filter for writing files in the ZIP file format. Includes support for both compressed and uncompressed entries. Constructor : ZipOutputStream(OutputStream out) : Creates a new ZIP output stream. ZipOutputStream(OutputStream out, Charset charset) : Creates a new 3 min read Compressing and Decompressing files in Java DeflaterOutputStream and InflaterInputStream  classes are provided in Java to compress and decompress the file contents. These classes provide useful methods that can be used for compressing  the file content. Compressing a File using DeflaterOutputStream This class implements an output stream filte 4 min read Java.util.zip.InflaterInputStream class in Java This class implements a stream filter for uncompressing data in the "deflate" compression format. It is also used as the basis for other decompression filters, such as GZIPInputStream. Constructors InflaterInputStream(InputStream in) : Creates a new input stream with a default decompressor and buffe 3 min read Java.util.zip.InflaterOutputStream class in Java This class implements an output stream filter for uncompressing data stored in the "deflate" compression format. Constructors InflaterOutputStream(OutputStream out) : Creates a new output stream with a default decompressor and buffer size. InflaterOutputStream(OutputStream out, Inflater infl) : Crea 3 min read Like