解压缩文件

/**
     * 解压缩一个文件
     *
     * @param zipFile 压缩文件
     * @param folderPath 解压缩的目标目录
     */
    public void upZipFile(final File zipFile, final String folderPath, final int itaskid){
    Log.i(Tag, Tag + " zipFile: "+zipFile+" folderPath: " + folderPath + " itaskid: " + itaskid);
    final int iTaskid = itaskid;
    final int BUFF_SIZE = 1024 * 1024; // 1M Byte
    new Thread() {
public void run() {
File desDir = new File(folderPath);
if (!desDir.exists()) {
desDir.mkdirs();
}
try {
ZipFile zf = new ZipFile(zipFile);
for (Enumeration<?> entries = zf.entries(); entries
.hasMoreElements();) {
ZipEntry entry = ((ZipEntry) entries.nextElement());
InputStream in = zf.getInputStream(entry);
// String str = folderPath + File.separator+"sound"
// + entry.getName();
String str = folderPath + entry.getName();
str = new String(str.getBytes("8859_1"), "GB2312");
File desFile = new File(str);
Log.i(Tag, Tag + "zipfilename"+str);
if(str.contains(".ogg"))
{
if(!desFile.exists()){
desFile.createNewFile();
}
}else{
if(!desFile.exists()){
desFile.mkdir();
}
continue;
}

OutputStream out = new FileOutputStream(desFile);
byte buffer[] = new byte[BUFF_SIZE];
int realLength;
while ((realLength = in.read(buffer)) > 0) {
out.write(buffer, 0, realLength);
}
out.flush();
out.flush();
in.close();
}
Message msg = new Message();
msg.what = Cocos2dxHandler.MT_COCOSCTIVITY_UNZIPRESULT;
Bundle shareBundle = new Bundle();
msg.setData(shareBundle);
shareBundle.putInt("RESULT", 1);
shareBundle.putInt("TASKID", iTaskid);
mtAndroidNativeBright.getCocosHandler().sendMessage(msg);

} catch (Exception e) {
// TODO: handle exception
Log.i(Tag, Tag + e.toString());
Message msg = new Message();
msg.what = Cocos2dxHandler.MT_COCOSCTIVITY_UNZIPRESULT;
Bundle shareBundle = new Bundle();
msg.setData(shareBundle);
shareBundle.putInt("RESULT", 0);
shareBundle.putInt("TASKID", iTaskid);
mtAndroidNativeBright.getCocosHandler().sendMessage(msg);
}
}
}.start();
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值