JAVA ZipFile解凍zip

2686 ワード

JAVA ZipFile解凍zip
このMarkdownエディタは[StackEdit][6]を使用して修正され、ブログを書くと、新しい体験が得られます.
コードブロック
int buffSize=204800;
Charset charset=Charset.forName("GBK");
String srcPath="C:\\Users\\Joue\\Desktop\\     .zip";
String exPath="C:\\Users\\Joue\\Desktop\\";
ZipFile zipFile=new ZipFile(srcPath,charset);
Enumeration enumeration=(Enumeration)zipFile.entries();
while (enumeration.hasMoreElements()) {
    try {
    ZipEntry zipEntry=enumeration.nextElement();
        if(zipEntry.isDirectory()) {//   
            File file=new File(exPath+zipEntry.getName());
            if (!file.exists()){
                file.mkdir();
            }
        }
        else {
            FileOutputStream fileOutputStream = new FileOutputStream(exPath + zipEntry.getName());
            InputStream inputStream=zipFile.getInputStream(zipEntry);
            int count=0,tinybuff=buffSize;
            if(inputStream.available()//         
            }
            byte[] datas=new byte[tinybuff];
            while ((count=inputStream.read(datas,0,tinybuff))!=-1){//        -1          
                fileOutputStream.write(datas,0,count);
                if(inputStream.available()else tinybuff=buffSize;
                datas=new byte[tinybuff];
            }
            fileOutputStream.flush();//    
            fileOutputStream.close();
        }
    }
    catch (Exception e){
        e.printStackTrace();
    }
}
zipFile.close();