读取zip,过滤中文名称 分类: java 2009-11-06 22:46 385人阅读 评论(0) 收藏
2009-11-06 22:46
525 查看
import java.io.BufferedInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; FileOutputStream fos = null; try{ //读取到本地硬盘中 fos = new FileOutputStream(new File("e://icon.zip")); fos.write(bt); fos.flush(); fos.close(); //读取mobile2.zip中的内容到images/background/mobile2 ZipFile zfile = new ZipFile("e://icon.zip"); Enumeration zList = zfile.entries(); byte[] buf = new byte[1024]; while (zList.hasMoreElements()) { ZipEntry ze = (ZipEntry) zList.nextElement(); if (ze.isDirectory()) { continue; } String icon_name = CharSet.toGB2312(ze.getName()); boolean isChinese = false; byte[] b = icon_name.getBytes(); for(int i=0;i<b.length;i++){ //判断图标名称是否含有中文,只要含有中文,就进行下一轮循环。b[i]=0时时中文,b[i]=63时是'?' if(b[i]<0 || b[i]==63){ isChinese = true; break; } } if(isChinese){ continue; } // 以ZipEntry为参数得到一个InputStream,并写到OutputStream中 OutputStream os = new BufferedOutputStream(new FileOutputStream(getServletContext().getRealPath("/")+"images//background//mobile2//"+icon_name)); InputStream is = new BufferedInputStream(zfile.getInputStream(ze)); int readLen = 0; while ((readLen = is.read(buf)) != -1) { os.write(buf, 0, readLen); } os.close(); is.close(); } zfile.close(); }catch(Exception e){ e.printStackTrace(); }
相关文章推荐
- 读取zip,不过滤中文名,即中文名称也能成功读取 分类: java 2009-11-06 22:48 296人阅读 评论(0) 收藏
- android 判断字符串是否为数字或中文或字母 分类: Android JAVA 2015-06-07 21:07 29人阅读 评论(0) 收藏
- Socket读取输入流 分类: java 2010-03-22 17:38 3330人阅读 评论(0) 收藏
- Java读取文件内容的几种方式 分类: Java 2015-07-20 17:55 2人阅读 评论(0) 收藏
- 解决Eclipse中文乱码 分类: B1_JAVA 2014-06-25 11:23 336人阅读 评论(0) 收藏
- 【JAVA编码专题】深入分析 Java 中的中文编码问题 分类: B1_JAVA 2015-02-10 21:09 153人阅读 评论(0) 收藏
- 解决linux下java读取串口之权限问题 No permission to create lock file. 分类: LINUX 2010-07-13 20:51 2006人阅读 评论(0) 收藏
- 关于如何在java中实现中文首字母索引排序的问题 2016-08-25 15:14 86人阅读 评论(0) 收藏 举报 分类: Java(19) 版权声明:本文为博主原创文章,未经博主允许不得转载
- Java中的日期操作 分类: B1_JAVA 2015-02-16 17:55 6014人阅读 评论(0) 收藏
- Android的sdk、api及工程目录说明 分类: JAVA 2015-01-16 16:20 365人阅读 评论(0) 收藏
- POI操作Excel常用方法总结 分类: B1_JAVA 2013-08-23 10:01 349人阅读 评论(0) 收藏
- 第四章 类与对象 分类: java 2009-12-29 16:45 322人阅读 评论(0) 收藏
- UDP:Java实现简单大文件传输 分类: 网络通讯 2014-09-21 20:21 320人阅读 评论(0) 收藏
- 使用C语言读取properties文件V1.0 分类: H_HISTORY 2013-02-26 12:37 946人阅读 评论(0) 收藏
- 01-Jvm 内存区域复习笔记 分类: JVM Java 2015-07-16 12:52 139人阅读 评论(0) 收藏
- 详解python linecache模块读取文件的方法 分类: python Module 2014-07-21 18:32 1057人阅读 评论(0) 收藏
- JAVA 对象数组,加载图片实例 分类: Java Game 2014-08-14 16:57 80人阅读 评论(0) 收藏
- java.lang.IllegalArgumentException: <session-config> element is limited to 1 occurrence 分类: Tomcat 2014-12-09 11:20 512人阅读 评论(0) 收藏
- 集合类... 分类: java 2009-11-02 14:22 193人阅读 评论(0) 收藏
- 使用nextInt()等接受输入时必须注意换行符的输入 分类: B1_JAVA 2013-10-12 16:21 1755人阅读 评论(0) 收藏