zoukankan      html  css  js  c++  java
  • android 解压zip中特定文件

     1 /**
     2      * 解压文件名包含传入文字的文件
     3      *
     4      * @param zipFile 压缩文件
     5      * @param folderPath 目标文件夹
     6      * @param nameContains 传入的文件匹配名
     7      * @throws ZipException 压缩格式有误时抛出
     8      * @throws IOException IO错误时抛出
     9      */
    10     public static ArrayList<File> upZipSelectedFile(File zipFile, String folderPath,
    11             String nameContains) throws ZipException, IOException {
    12         ArrayList<File> fileList = new ArrayList<File>();
    13   
    14         File desDir = new File(folderPath);
    15         if (!desDir.exists()) {
    16             desDir.mkdir();
    17         }
    18   
    19         ZipFile zf = new ZipFile(zipFile);
    20         for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements();) {
    21             ZipEntry entry = ((ZipEntry)entries.nextElement());
    22             if (entry.getName().contains(nameContains)) {
    23                 InputStream in = zf.getInputStream(entry);
    24                 String str = folderPath + File.separator + entry.getName();
    25                 str = new String(str.getBytes("8859_1"), "GB2312");
    26                 // str.getBytes("GB2312"),"8859_1" 输出
    27                 // str.getBytes("8859_1"),"GB2312" 输入
    28                 File desFile = new File(str);
    29                 if (!desFile.exists()) {
    30                     File fileParentDir = desFile.getParentFile();
    31                     if (!fileParentDir.exists()) {
    32                         fileParentDir.mkdirs();
    33                     }
    34                     desFile.createNewFile();
    35                 }
    36                 OutputStream out = new FileOutputStream(desFile);
    37                 byte buffer[] = new byte[BUFF_SIZE];
    38                 int realLength;
    39                 while ((realLength = in.read(buffer)) > 0) {
    40                     out.write(buffer, 0, realLength);
    41                 }
    42                 in.close();
    43                 out.close();
    44                 fileList.add(desFile);
    45             }
    46         }
    47         return fileList;
    48     }

    参考:http://www.itstrike.cn/Question/4f10bddd-2bb5-4e61-ad11-d22efa828861.html

  • 相关阅读:
    springboot访问项目中某个module的图片(服务器拿不到)
    ValidForm ajaxurl 进行表单验证检验用户名是否存在
    jrebel热部署配置
    form标签之form:checkboxes
    springboot 整合jsp过程中的一些问题
    springboot的一些配置
    mysql5.7解压版
    [转载][翻译] 利用JSF、SpringFramework和Hibernate构建Web应用的实例讲述
    获取本机MAC地址
    个人职业生涯讨论
  • 原文地址:https://www.cnblogs.com/Miami/p/5259153.html
Copyright © 2011-2022 走看看