java 过滤.zip_读取zip,过滤中文名称 分类: java ...

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[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();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值