<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 閱讀(362) 評論(0)  編輯  收藏 所屬分類: J2SE

    主站蜘蛛池模板: 免费人成视频在线| 精品国产呦系列在线观看免费| 亚洲精品456在线播放| 亚洲国产综合专区电影在线 | 久久成人18免费网站| 日韩精品无码永久免费网站| 日韩成人毛片高清视频免费看| 思思久久99热免费精品6| 无码免费又爽又高潮喷水的视频| 特级一级毛片免费看| 一个人看的免费视频www在线高清动漫| 特a级免费高清黄色片| 中国一级毛片免费看视频| 久久国产精品成人免费| 狼群影院在线观看免费观看直播| 我的小后妈韩剧在线看免费高清版| 国产男女爽爽爽爽爽免费视频| 久久天天躁狠狠躁夜夜免费观看| 国内自产少妇自拍区免费| 免费日本黄色网址| 亚洲欧洲国产精品香蕉网| 亚洲免费精彩视频在线观看| 亚洲国产日产无码精品| 亚洲AV综合色区无码一二三区| 免费福利资源站在线视频| 99re6在线视频精品免费| 18禁成人网站免费观看| 免费理论片51人人看电影| 亚洲男人第一无码aⅴ网站| 亚洲AV无码一区东京热| 亚洲av成人一区二区三区| 国产精品亚洲色图| 国产成人免费AV在线播放| 日本妇人成熟免费中文字幕| 国产精品久久免费视频| 亚洲精品无码久久久影院相关影片| 亚洲综合在线成人一区| 亚洲AV无码之国产精品| A片在线免费观看| 成人男女网18免费视频| 中文字幕精品亚洲无线码一区|