在研究如何遍历Assets下的文件时,我得到了一点奇怪的结果 - 看到了一些本不属于当前应用的文件结构。
首先贴一下遍历代码
public static void printAssets(Context c) {
AssetManager am = c.getAssets();
printAssetsFiles(am, "", "");
}
public static void printAssetsFiles(AssetManager am, String parent, String current, String indent) {
if (!TextUtils.isEmpty(current)) {
System.out.println(indent + current);
indent += "\t";
}
// 列出子文件
String[] files;
String currentParent;
try {
if (TextUtils.isEmpty(parent)) {
currentParent = current;
} else {
currentParent = parent + "/" + current;
}
files = am.list(currentParent);
} catch (IOException e1) {
return;
}
if (files != null && files.length > 0) {
for (String f : files) {