<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    paulwong

    解壓ZIP文件

    在pom.xml中加入JAR包
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
    </dependency>

    ZipUtil.java
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.nio.charset.Charset;
    import java.util.UUID;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipInputStream;

    import org.apache.commons.io.IOUtils;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;

    public class ZipUtil {
        
        private static Logger logger = LoggerFactory.getLogger(ZipUtil.class);
        
        public static void extractFolder(InputStream inputStream, String outputFolder) throws IOException 
        {
            ZipInputStream zis = null;
            try {

                Charset GBK = Charset.forName("GBK");
                zis = new ZipInputStream(inputStream, GBK);
                ZipEntry entry;

                while ((entry = zis.getNextEntry()) != null) {

                    // Create a file on HDD in the destinationPath directory
                    
    // destinationPath is a "root" folder, where you want to extract your ZIP file
                    String encoding = System.getProperty("file.encoding");
                    logger.info("encoding:"+encoding); 
                    
                    String fileName = new String(entry.getName().getBytes("GBK"), encoding);
                    File entryFile = new File(outputFolder, fileName);
    //                File entryFile = new File(outputFolder, entry.getName());
                    if (entry.isDirectory()) {

                        if (entryFile.exists()) {
                            logger.warn("Directory {0} already exists!", entryFile);
                        } else {
                            entryFile.mkdirs();
                        }

                    } else {

                        // Make sure all folders exists (they should, but the safer, the better ;-))
                        if (entryFile.getParentFile() != null && !entryFile.getParentFile().exists()) {
                            entryFile.getParentFile().mkdirs();
                        }

                        // Create file on disk
                        if (!entryFile.exists()) {
                            entryFile.createNewFile();
                        }

                        // and rewrite data from stream
                        OutputStream os = null;
                        try {
                            os = new FileOutputStream(entryFile);
                            IOUtils.copy(zis, os);
                        } finally {
    //                        os.close();
                            IOUtils.closeQuietly(os);
                            zis.closeEntry();
                        }
                    }
                }
            } finally {
                IOUtils.closeQuietly(zis);
            }
        }
        
        public static void main(String [] args) throws IOException
        {
            final String INPUT_ZIP_FILE = "D:TESTING-FILE/ZIP/INPUT/應(yīng)用.zip";
            String OUTPUT_FOLDER = "D:/TESTING-FILE/ZIP/OUTPUT";
            
            OUTPUT_FOLDER += File.separator + UUID.randomUUID().toString();
            
            InputStream inputStream = new FileInputStream(new File(INPUT_ZIP_FILE));
            
            extractFolder(inputStream, OUTPUT_FOLDER);
            
            /*File file = new File(OUTPUT_FOLDER);
            FileUtil.deleteFolder(file);
    */
        }

    }

    posted on 2014-10-29 17:34 paulwong 閱讀(364) 評(píng)論(0)  編輯  收藏 所屬分類: J2SE

    主站蜘蛛池模板: 亚洲人成黄网在线观看| 四虎影视大全免费入口| 亚洲成av人片在线观看无码不卡| 又硬又粗又长又爽免费看| 免费在线观看中文字幕| 免费看又黄又爽又猛的视频软件| 国产一级淫片a视频免费观看| 国产亚洲人成在线影院| 午夜亚洲av永久无码精品| 在线播放免费人成视频网站| 亚洲Av无码乱码在线播放| 一二三区免费视频| 国产成人A人亚洲精品无码| 99在线视频免费观看| 久久亚洲AV成人无码电影| 无码乱肉视频免费大全合集 | 青草草色A免费观看在线| 91亚洲国产成人久久精品网址| 美女网站免费福利视频| 亚洲AV电影天堂男人的天堂| 免费播放春色aⅴ视频| 久久嫩草影院免费看夜色| 99久久亚洲精品无码毛片| 成年18网站免费视频网站| 色吊丝免费观看网站| 亚洲人成在线播放网站| 国产精品成人观看视频免费| 无码天堂亚洲国产AV| 国产成人亚洲综合无码精品| 一二三四影视在线看片免费| 日韩亚洲翔田千里在线| 久久精品国产亚洲夜色AV网站 | 成年人免费视频观看| 四虎一区二区成人免费影院网址| 亚洲精品美女久久777777| 免费精品国产自产拍在| 免费无码又爽又黄又刺激网站| 亚洲成色在线影院| 成人永久免费高清| 免费国产黄网站在线观看视频| 亚洲成aⅴ人片久青草影院按摩|