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(); }