Home  >  Core Java

Example of DeflaterOutputStream in Java

By Arvind Rai, April 13, 2013
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.
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
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us