解压完android空文件夹,在Android中解压缩文件夹

你可以将你的.zip文件包含在apk的Assets文件夹中,并将它们放在代码中,将.zip复制到内部存储并使用ZipInputStream进行解压缩。

首页复印德.zip文件的内部存储,并解压缩文件后:

protected void copyFromAssetsToInternalStorage(String filename){

AssetManager assetManager = getAssets();

try {

InputStream input = assetManager.open(filename);

OutputStream output = openFileOutput(filename, Context.MODE_PRIVATE);

copyFile(input, output);

} catch (IOException e) {

e.printStackTrace();

}

}

private void unZipFile(String filename){

try {

ZipInputStream zipInputStream = new ZipInputStream(openFileInput(filename));

ZipEntry zipEntry;

while((zipEntry = zipInputStream.getNextEntry()) != null){

FileOutputStream zipOutputStream = openFileOutput(zipEntry.getName(), MODE_PRIVATE);

int length;

byte[] buffer = new byte[1024];

while((length = zipInputStream.read(buffer)) > 0){

zipOutputStream.write(buffer, 0, length);

}

zipOutputStream.close();

zipInputStream.closeEntry();

}

zipInputStream.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

private void copyFile(InputStream in, OutputStream out) throws IOException {

byte[] buffer = new byte[1024];

int read;

while((read = in.read(buffer)) != -1){

out.write(buffer, 0, read);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值