zoukankan      html  css  js  c++  java
  • GZIPOutputStream GZIPInputStream

    GZIP is appropriate for single data stream.

    Example: Compress one file

    public class Demo8 {
     
     public static void main(String[] args) throws Exception {
      //read a file
      FileReader fr = new FileReader("C:/Users/caich5/Desktop/aaaa.txt");
      
            BufferedReader in = new BufferedReader(fr);
           
            //starting to compress
            FileOutputStream fos = new FileOutputStream("C:/Users/caich5/Desktop/aaaa.gz");
            GZIPOutputStream gzipout = new GZIPOutputStream(fos);
            BufferedOutputStream bos = new BufferedOutputStream(gzipout);
           

            int c;
            while((c = in.read())!= -1){
             bos.write(c);
            }
            in.close();
            bos.close();
            
            //reading  gzip file 
            FileInputStream fis = new FileInputStream("C:/Users/caich5/Desktop/aaaa.gz");
            GZIPInputStream gzipin = new GZIPInputStream(fis);
            InputStreamReader isr = new InputStreamReader(gzipin);
            BufferedReader in2 = new BufferedReader(isr);
           
            String s;
            while((s = in2.readLine())!= null){
             System.out.println(s);
             
            }
     }
    }

    Aimer,c'est partager
  • 相关阅读:
    js 对象合并
    python3 TypeError: 'str' does not support the buffer interface in python
    django rest framework 再撸体验
    linux shell输入重定向
    httpie 取代 curl
    wget 断点续传 & nginx文件服务器
    select2 demo
    vmare centos 6.8 minimal 无法上网
    protocol http not supported or disabled in libcurl apt-get
    python3 -pip
  • 原文地址:https://www.cnblogs.com/pickKnow/p/8515381.html
Copyright © 2011-2022 走看看