首页 > 其他 > 详细

压缩/解压缩gz

时间:2016-08-17 01:32:57      阅读:253      评论:0      收藏:0      [点我收藏+]

压缩/解压缩gz

 1 public class GZIPcompress {
 2 
 3     public static void FileCompress(String file, String outgz) throws IOException {
 4         BufferedReader br = new BufferedReader(new FileReader(file));
 5         BufferedOutputStream bs = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(outgz)));
 6 
 7         int c;
 8         while ((c = br.read()) != -1) {
 9             bs.write(c);
10         }
11         br.close();
12         bs.close();
13     }
14 
15     public static String FileUnCompress(String filegz) throws IOException {
16         BufferedReader bf = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(filegz))));
17         String s;
18         StringBuffer sb = new StringBuffer();
19         while ((s = bf.readLine()) != null) {
20             sb.append(s);
21         }
22         bf.close();
23         return sb.toString();
24     }
25 
26     public static void main(String[] args) throws IOException {
27         String fileOut = "test.gz";
28         String in = "test.txt";
29         
30         FileCompress(in, fileOut);
31         String out = FileUnCompress(fileOut);
32         
33         System.err.println(out);
34     }
35 
36 }

 

压缩/解压缩gz

原文:http://www.cnblogs.com/luangeng/p/5778379.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!