1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Android 将Assets 目录中的ZIP压缩包解压至本地指定文件中

Android 将Assets 目录中的ZIP压缩包解压至本地指定文件中

时间:2021-09-19 04:48:38

相关推荐

Android 将Assets 目录中的ZIP压缩包解压至本地指定文件中

/*** 解压Assets目录下ZIP包** @param context 上下文* @param assetName 被解压的压缩包名称* @param outputDirectory 解压后存放的路径*/public static void unZipFromAssets(Context context, String assetName, String outputDirectory) {try {InputStream dataSource = context.getAssets().open(assetName);ZipInputStream in = new ZipInputStream(dataSource);ZipEntry entry = in.getNextEntry();while (entry != null) {LOG.debug("CAR-SHOW", "unZipFromAssets ZipEntry name = " + entry.getName());// 创建以zip包文件名为目录名的根目录File file = new File(outputDirectory);if (!file.exists()){file.mkdirs();}if (entry.isDirectory()) {String name = entry.getName();name = name.substring(0, name.length() - 1);file = new File(outputDirectory + File.separator + name);if (!file.exists()){file.mkdir();}} else {file = new File(outputDirectory + File.separator + entry.getName());if (!file.exists()){file.createNewFile();FileOutputStream out = new FileOutputStream(file);byte[] buffer = new byte[1024];int length;while ((length = in.read(buffer)) > 0) {out.write(buffer, 0, length);}out.close();}}// 读取下一个ZipEntryentry = in.getNextEntry();}in.close();} catch (IOException e) {e.printStackTrace();}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。