python不解压直接提取文件_不解压直接读取压缩包中的文件

本文介绍如何在不解压的情况下,使用Java的ZipFile类从压缩包中读取特定文件,并将其写入Android项目的指定目录,以优化移动端的用户体验,避免长时间等待和程序崩溃。
摘要由CSDN通过智能技术生成

接下来我们对上面的方法进行改造,将指定文件从压缩包中读取出来并写入到指定的目录下,以便于在Android项目中进行查看

/**

*

* @param file 压缩包路径

* @param saveRootDirectory 写入文件夹路径

* @param fileName 文件名

* @throws FileNotFoundException

* @throws IOException

*/

public static void writeZipFile(String file,String saveRootDirectory,String fileName) throws FileNotFoundException, IOException {

int len = 0;

ZipFile zf = new ZipFile(file);

ZipEntry ze = zf.getEntry(fileName);

InputStream read = zf.getInputStream(ze);

File writeFile = new File(saveRootDirectory + fileName);

if (!writeFile.exists()) {

File rootDirectoryFile = new File(saveRootDirectory);

//创建目录

if (!rootDirectoryFile.exists()) {

rootDirectoryFile.mkdirs();

}

//创建文件

writeFile.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值