Powered by Blogger.

8). Program for reading the data from Zipped file using java

>> Wednesday, May 4, 2011

Uncompress the data from a zipped file using java.


 To Convert the contents present in zip_hello file to the original data then the class InflatorInputStream is used.This class is used to convert unreadable format data to the readable format.


InflaterInputStream iis = new InflaterInputStream(fis);


While creating the object of this class it expects FileInputStream class object (fis) as an argument.

InflatorInputStream class is available in java.util.zip package.

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.

This contains some of the methods:

int available()

void close()

int read()

void reset()

package javabynataraj.iopack;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.InflaterInputStream;

public class Uncompress {
    public static void main(String[] args)throws IOException {
        
        FileInputStream fis = new FileInputStream("zip_hello");
        InflaterInputStream iis = new InflaterInputStream(fis);
        FileOutputStream fos = new FileOutputStream("temp2.dat");
        
        int ch;
        while((ch=iis.read())!=-1){
            fos.write(ch);
        }
        iis.close();
        fis.close();
        fos.close();
        System.out.println("File Uncompressed....");
    }
}


Note: We are passing the arguments as files to FileInputStream and FileOutputStream classes.
           Here these files will be stored at one place.Fist file is already zipped file we have to put readily for FileInputStream class.

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2022. All rights reserved.