最后,我编写了自己的实现。
public class FileStructure {
public final String pathName;
// or TreeMap if order matter
public HashMap<String, FileStructure> files;
public FileStructure(String path){
this.pathName = path;
files = new HashMap<String, FileStructure>();
}
}
使用 java.util.zip.ZipFile 获取 apk 扩展文件条目:
ZipFile zf = new ZipFile(Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/Android/obb/" + getPackageName()
+ "/main.1." + getPackageName() + ".obb");
Enumeration zipEntries = zf.entries();
String fname;
while (zipEntries.hasMoreElements()) {
fname = ((ZipEntry) zipEntries.nextElement()).getName();
addToRoot(fname, root);
}
并在 FileStructure 类中解析它
private void addToRoot(String fname, FileStructure root) {
String[] directories = fname.split(File.separator);
FileStructure current = root;
for (int i = 0; i < directories.length; i++) {
if (!current.files.containsKey(directories[i])) {
current.files.put(directories[i], new FileStructure(directories[i]));
}
current = current.files.get(directories[i]);
}
}
但是,如果有人分享一些更好的解决方案或发现我的实施存在缺陷,我将不胜感激!