Extract .gz files in java

本秂侑毒 提交于 2020-01-03 15:12:06

问题


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

when i try to execute it i get this error: java.util.zip.ZipException: Not in GZIP format

how can i solve it? Thanks in advance for your help

来源:https://stackoverflow.com/questions/40999813/extract-gz-files-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!