7). Program to Zipping the contents present with in the file.
Making a file into unreadable format.
To Zip the contents present with in a file the class DeflatorOutputStream is used.This class is defined with in the util package.
The Object of DeflatorOutputStream class will expect FileOutputStream object as an argument.
Code:
To Zip the contents present with in a file the class DeflatorOutputStream is used.This class is defined with in the util package.
DeflaterOutputStream dos = new DeflaterOutputStream(fos);
The Object of DeflatorOutputStream class will expect FileOutputStream object as an argument.
Code:
package javabynataraj.iopack; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.DeflaterOutputStream; public class UnreadableFile { public static void main(String[] args)throws IOException { FileInputStream fis = new FileInputStream("hello2.dat"); FileOutputStream fos = new FileOutputStream("zip_hello"); DeflaterOutputStream dos = new DeflaterOutputStream(fos); int ch; while((ch = fis.read())!= -1){ dos.write(ch); } dos.close(); fos.close(); fis.close(); System.out.println("done........"); } }