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
  • 相关阅读:
    jQuery火箭图标返回顶部代码
    类库引用EF
    Html.DropDownList
    MVC validation
    MVC @functions
    MVC 扩展方法特点
    Class 实现IDisposing方法
    MVC两个必懂核心
    Asp.net 服务器Application,Session,Cookie,ViewState和Cache区别
    sqlserver log
  • 原文地址:https://www.cnblogs.com/pickKnow/p/8515381.html
Copyright © 2011-2022 走看看