zoukankan      html  css  js  c++  java
  • ZipUtil

    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package cast.c514.transfer.util;

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

    /**
     *
     * @author cuizhf
     */
    public class MyZipUtil {

        private MyZipUtil() {
        }

        /**
         * 执行压缩文件的解压,并自动生成文件的操作
         *
         * @throws java.io.IOException
         * @see http://blog.csdn.net/isea533/article/details/7995472
         * @param in
         * @param outputDirectory
         */
        public static void unZip(InputStream in, String outputDirectory) throws IOException {
            // 通过Charset.forName("GBK")解决乱码问题
            try (ZipInputStream zins = new ZipInputStream(in, Charset.forName("GBK"))) {
                ZipEntry ze;
                byte[] ch = new byte[256];
                while ((ze = zins.getNextEntry()) != null) {
                    File zfile = new File(outputDirectory + File.separator + ze.getName());
                    File fpath = new File(zfile.getParentFile().getPath());
                    if (ze.isDirectory()) {
                        if (!zfile.exists()) {
                            zfile.mkdirs();
                        }
                        zins.closeEntry();
                    } else {
                        if (!fpath.exists()) {
                            fpath.mkdirs();
                        }
                        try (FileOutputStream fouts = new FileOutputStream(zfile)) {
                            int i;
                            while ((i = zins.read(ch)) != -1) {
                                fouts.write(ch, 0, i);
                            }
                            zins.closeEntry();
                        }
                    }
                }
            }
        }
    }

  • 相关阅读:
    解决Xcode8打印了nw_socket_handle_socket_event Event mask
    调用系统框架使用设备系统语言的设置,相册相机设置为中文
    ios开发 之 设置多种文字颜色/背景色/文字下划线/行间距 NSString
    IOS 开发中 Whose view is not in the window hierarchy 错误的解决办法
    UITableView设置cell的separator 分割线
    iOS用户点击推送消息进入应用后自动跳转到对应的ViewController
    随感
    JS获取当前网页大小以及屏幕分辨率等
    js将秒转换为 分:秒 函数
    css实现强制不换行/自动换行/强制换行
  • 原文地址:https://www.cnblogs.com/cuizhf/p/7566679.html
Copyright © 2011-2022 走看看