DeflaterInputStream and InflaterOutputStream in Java

Written by: Arvind Rai,
Last updated:
November 13, 2023
On this page we will learn using DeflaterInputStream and InflaterOutputStream in our Java application.

DeflaterInputStream

DeflaterInputStream and InflaterOutputStream belong to Java 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

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();
      }   
 }

Join the Newsletter

(Subscribe to get our latest content directly into your inbox)

WRITTEN BY
ARVIND RAI
ARVIND RAI









©2024 concretepage.com | Privacy Policy | Contact Us