Home  >  Core Java

DeflaterInputStream and InflaterOutputStream in Java

By Arvind Rai, April 17, 2013
DeflaterInputStream and InflaterOutputStream belong to jdk 1.6. DeflaterInputStream compresses data in DEFLATE format and provides input stream. Find the example for DeflaterInputStream.
DeflaterInputStreamTest.java
package com.concretepage;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.DeflaterInputStream;
import java.util.zip.DeflaterOutputStream;
public class DeflaterInputStreamTest {
    public static void main(String[] args) throws Exception {
        FileInputStream in = new FileInputStream("D:\\page\\file.txt");
        FileOutputStream out = new FileOutputStream("D:\\page\\file.dfl");
        DeflaterInputStream dis = new DeflaterInputStream(in);
        int ch=0;
        while ((ch = in.read())!=-1){
           ch = in.read();
           out.write(ch);
        }
        dis.close();
        in.close();
        out.close();
      }   
 }
InflaterOutputStream uncompresses DEFLATE format data and provides output stream. Find the example for InflaterOutputStream.
InflaterOutputStreamTest.java
package com.concretepage;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.InflaterOutputStream;
public class InflaterOutputStreamTest {
    public static void main(String[] args) throws Exception {
        FileInputStream in = new FileInputStream("D:\\page\\file.dfl");
        FileOutputStream out = new FileOutputStream("D:\\page\\dfloutput.txt");
        InflaterOutputStream ios = new InflaterOutputStream(out);
        int ch=0;
        while ((ch = in.read())!=-1){
           ch = in.read();
           ios.write(ch);
        }
        ios.close();
        in.close();
        out.close();
      }   
 }
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us