android解压zip
2023-12-14 17:52:04
private static String aikitPathReal = "/obb/"; private static String aikitPathInData = "";
File sdDir = new File(mContext.getFilesDir(), aikitPathReal);///data/user_de/0/org.cocos2d.demo/files/obb/ aikitPathInData = sdDir.getAbsolutePath() + "/"; if (FileUtils.isDirectoryEmpty(aikitPathInData)) { FileUtils.createDirectory(aikitPathInData); try { FileUtils.copyFiles(mContext, "xtts", aikitPathInData); FileUtils.unZip(aikitPathInData+"/assets.obb"); System.out.print("--------2--------"); } catch (IOException e) { e.printStackTrace(); } } else { System.out.print("------1----------"); }
public static void unZip(String SourceDir) throws IOException { unZip(SourceDir, new File(SourceDir).getParent(), ""); } public static void unZip(String SourceDir, String extDir) throws IOException { unZip(SourceDir, extDir, ""); } public static void unZip(String SourceDir, String extDir, String fileExt) throws IOException { ZipFile zip = new ZipFile(SourceDir); Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String name = entry.getName(); if (!name.startsWith(fileExt)) continue; String path = name; if (entry.isDirectory()) { File f = new File(extDir + File.separator + path); if (!f.exists()) f.mkdirs(); } else { String fname = extDir + File.separator + path; File temp = new File(fname).getParentFile(); if (!temp.exists()) { if (!temp.mkdirs()) { throw new RuntimeException("create file " + fname + temp.getName() + " fail"); } } try { path = path.replaceAll("[\r\n]", ""); FileOutputStream out = new FileOutputStream(extDir + File.separator + path); InputStream in = zip.getInputStream(entry); byte[] buf = new byte[8 * 1000]; int count = 0; while ((count = in.read(buf)) != -1) { out.write(buf, 0, count); } out.close(); in.close(); } catch (Exception e) { e.printStackTrace(); } } } zip.close(); //AppActivity.downloadFileLanguageOver(); }
文章来源:https://blog.csdn.net/alengan/article/details/134998203
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!