Click here to watch in Youtube :
https://www.youtube.com/watch?v=ckapaBc-vd4&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java IO (Java File - Compressing and Decompressing File - Deflater) |
Java Tutorial : Java IO (Java File - Compressing and Decompressing File - Deflater) |
Java Tutorial : Java IO (Java File - Compressing and Decompressing File - Deflater) |
Java Tutorial : Java IO (Java File - Compressing and Decompressing File - Deflater) |
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.DeflaterOutputStream; class CompressFileDemo { public static void main(String args[]) throws IOException { CompressFileDemo compressFileDemo = new CompressFileDemo(); compressFileDemo.compressFile("D:/work/HelloWorld.java", "D:/work/Compressed.txt"); } private void compressFile(String fileToCompress, String compressFile) throws IOException { try ( FileInputStream fin = new FileInputStream(fileToCompress); FileOutputStream fout = new FileOutputStream(compressFile); DeflaterOutputStream dos = new DeflaterOutputStream(fout);) { int i; while ((i = fin.read()) != -1) { dos.write((byte) i); dos.flush(); } } System.out.println("Compression is done.."); } }Output
Compression is done..
DecompressFileDemo.javaimport java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.InflaterInputStream; public class DecompressFileDemo { public static void main(String[] args) throws IOException { DecompressFileDemo decompressFileDemo = new DecompressFileDemo(); decompressFileDemo.decompressFile("D:/work/Compressed.txt", "D:/work/HelloWorld.java"); } private void decompressFile(String fileToDeCompress, String deCompressFile) throws IOException { try ( FileInputStream fin = new FileInputStream(fileToDeCompress); InflaterInputStream in = new InflaterInputStream(fin); FileOutputStream fout = new FileOutputStream(deCompressFile);) { int i; while ((i = in.read()) != -1) { fout.write((byte) i); fout.flush(); } } System.out.println("DeCompression is done.."); } }Output
DeCompression is done..
Refer: https://en.wikipedia.org/wiki/DEFLATE
https://docs.oracle.com/javase/8/docs/api/index.html?java/util/zip/DeflaterOutputStream.html
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_deflate_compress_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_deflate_compress_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/5edb9b935a4ef60d2a672d03f038390cd08d4eb7/BasicJava/JavaIODemo_deflate_compress_App/?at=master
See also:
No comments:
Post a Comment