<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/應用.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) 評論(0)  編輯  收藏 所屬分類: J2SE

    主站蜘蛛池模板: 免费在线观看理论片| 免费看少妇作爱视频| 亚洲精品无码不卡在线播HE| 免费视频成人国产精品网站| 国产在线观看www鲁啊鲁免费| 亚洲欧洲专线一区| 国产男女性潮高清免费网站| 国产精品亚洲一区二区三区在线观看 | 免费视频成人国产精品网站| 又大又粗又爽a级毛片免费看| 美女被免费视频网站| 亚洲国产香蕉人人爽成AV片久久 | 国产精品亚洲小说专区| 男人的天堂亚洲一区二区三区 | 永久免费无码网站在线观看个| 污污免费在线观看| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 亚洲AV人人澡人人爽人人夜夜| 最近中文字幕大全免费视频| 亚洲毛片一级带毛片基地| 日本一区二区三区免费高清| 大桥未久亚洲无av码在线| 亚洲午夜无码AV毛片久久| 18禁在线无遮挡免费观看网站| 亚洲精品免费视频| 天天干在线免费视频| 午夜成人无码福利免费视频| 亚洲一区二区三区首页| 无码人妻一区二区三区免费手机| 亚洲精华液一二三产区| 国产精品亚洲片在线观看不卡| 免费黄色福利视频| 国产成人高清亚洲一区91| 国产AV无码专区亚洲A∨毛片| 国产v精品成人免费视频400条| 黄色免费在线观看网址| 亚洲视频在线播放| 国产午夜免费秋霞影院| 青青草原1769久久免费播放| 亚洲综合色一区二区三区| 亚洲日韩精品一区二区三区无码|