欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java解压缩zip格式文件代码,java解压缩zip格式,package cn.o

来源: javaer 分享于  点击 18660 次 点评:28

java解压缩zip格式文件代码,java解压缩zip格式,package cn.o


package cn.outofmemory.snippets.core;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import java.util.zip.ZipEntry;import java.util.zip.ZipInputStream;public class DecompressZipFolder {    //The path of the zipped folder e.g. C:/Users/nikos7/Desktop/lib.zip    private static final String zippedFolderPath = "<ZIPPED FOLDER PATH>";     //The path of the output folder e.g. C:/Users/nikos7/Desktop    private static final String outputFolderPath = "<OUTPUT FOLDER PATH>";    public static void main(String[] args) throws Exception {        FileInputStream zippedFolder = new FileInputStream(zippedFolderPath);        ZipInputStream zippedInputStream = new ZipInputStream(new BufferedInputStream(zippedFolder));        ZipEntry entry;        while ((entry = zippedInputStream.getNextEntry()) != null) {            System.out.println("Unzipping: " + entry.getName());            int size;            byte[] buffer = new byte[2048];            FileOutputStream fileOutputStream = new FileOutputStream(outputFolderPath+"/"+entry.getName());            BufferedOutputStream bufferedOutputsStream = new BufferedOutputStream(fileOutputStream, buffer.length);            while ((size = zippedInputStream.read(buffer, 0, buffer.length)) != -1) {                bufferedOutputsStream.write(buffer, 0, size);            }            bufferedOutputsStream.flush();            bufferedOutputsStream.close();        }        zippedInputStream.close();        zippedFolder.close();    }}
相关栏目:

用户点评