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();
      }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM