解压缩功能

来源:互联网 发布:pdf转word 软件 编辑:程序博客网 时间:2024/05/21 14:45
public class ZipUtil{    /**    * 解压缩功能. 将ZIP_FILENAME文件解压到ZIP_DIR目录下.    *    * @throws Exception    */    public static void unZipFile(String sourceFile, String destFolder)throws Exception {        File fileDelete = new File(destFolder);                if (!fileDelete.exists()) {            fileDelete.mkdirs();        }                ZipFile zfile = new ZipFile(sourceFile);        //创建对象        Enumeration zList = zfile.getEntries();        ZipEntry ze = null;        byte[] buf = new byte[1024];        while (zList.hasMoreElements()) {            ze = (ZipEntry) zList.nextElement();            if (ze.isDirectory()) {                File f = new File(destFolder + ze.getName());                f.mkdir();                continue;            }            OutputStream os = new BufferedOutputStream(new FileOutputStream(            getRealFileName(destFolder, ze.getName())));            InputStream is = new BufferedInputStream(zfile.getInputStream(ze));            int readLen = 0;            while((readLen = is.read(buf, 0, 1024)) != -1) {                os.write(buf, 0, readLen);            }            is.close();            os.close();        }        zfile.close();        fileDelete = null;    }}

解压缩功能. 将ZIP_FILENAME文件解压到ZIP_DIR目录下.
0 0
原创粉丝点击