Example of DeflaterOutputStream in Java

By Arvind Rai, November 23, 2023
In Java DeflaterOutputStream provides output stream compressing data in DEFLATE format. In our example we have a file and in the file there is some test data. Using DeflaterOutputStream we will compress our test data in DEFLATE format.

Example

DeflaterOutputStreamTest.java
package com.concretepage;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.DeflaterOutputStream;
public class DeflaterOutputStreamTest {
    public static void main(String[] args) throws Exception {
        FileInputStream in = new FileInputStream("D:\\page\\file.txt");
        FileOutputStream out = new FileOutputStream("D:\\page\\file_new.dfl");
        DeflaterOutputStream dos = new DeflaterOutputStream(out);
        int ch=0;
        while ((ch = in.read())!=-1){
           ch = in.read();
           dos.write(ch);
        }
        dos.close();
        in.close();
      }   
 }
DeflaterOutputStream has written this file with the name file_new.dfl. We can find in the specified directory.
POSTED BY
ARVIND RAI
ARVIND RAI
LEARN MORE








©2024 concretepage.com | Privacy Policy | Contact Us