小编Ray*_*ark的帖子

Extract .gz files in java

I'm trying to unzip some .gz files in java. After some researches i wrote this method:

    public static void gunzipIt(String name){

    byte[] buffer = new byte[1024];

    try{

        GZIPInputStream gzis = new GZIPInputStream(new FileInputStream("/var/www/html/grepobot/API/"+ name + ".txt.gz"));
        FileOutputStream out = new FileOutputStream("/var/www/html/grepobot/API/"+ name + ".txt");

        int len;
        while ((len = gzis.read(buffer)) > 0) {
            out.write(buffer, 0, len);
        }

        gzis.close();
        out.close();

        System.out.println("Extracted " + name);

    } catch(IOException ex){
        ex.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

when i try to execute it i get this error: java.util.zip.ZipException: …

java gzip unzip

5
推荐指数
1
解决办法
4775
查看次数

标签 统计

gzip ×1

java ×1

unzip ×1