接下来我们对上面的方法进行改造,将指定文件从压缩包中读取出来并写入到指定的目录下,以便于在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.