java 解压.gz文件

1.//建立gzip压缩文件输入流 

2.建立gzip解压工作流

 fileInputStream = new FileInputStream(filePath + fileName);
            //解凍する
            GZIPInputStream Zin = new GZIPInputStream(fileInputStream);
            File outdir = new File(filePath);
            this.extractFile(Zin, outdir, "1.txt");

将文件流进行输出到文件

 private static void extractFile(GZIPInputStream in, File outdir, String name) throws IOException {
        byte[] buffer = new byte[BUFFER_SIZE];
        BufferedOutputStream out = new BufferedOutputStream(
            new FileOutputStream(new File(outdir, name)));
        int count = -1;
        while ((count = in.read(buffer)) != -1) {
          out.write(buffer, 0, count);
        }
        out.close();
      }

 

posted on 2017-04-06 17:28  手撕高达的村长  阅读(5740)  评论(0编辑  收藏  举报

导航