/**
* 遍历assets文件夹
*
* @param tab 格式化显示占位符
* @param path 在assets中的路径
*/
private void traverseAssets(String tab, String path) {
AssetManager assetManager = getAssets();
try {
// 获取path目录下,全部的文件、文件夹
String[] list = assetManager.list(path);
if (list == null || list.length <= 0) {
// 当前为文件时,或者当前目录下为空
return;
}
for (int i = 0; i < list.length; i++) {
System.out.println(tab + list[i]);
String subPath;
if ("".equals(path)) {
// 如果当前是根目录
subPath = list[i];
} else {
// 如果当前不是根目录
subPath = path + "/" + list[i];
}
traverseAssets(tab.concat("___"), subPath);
}
} catch (Exception e) {
e.printStackTrace();
}
}
// 从assets根目录开始遍历
traverseAssets("", "");
I/System.out: 1.txt
I/System.out: one
I/System.out: ___2.txt
I/System.out: ___two
I/System.out: ______3.txt
I/System.out: images
I/System.out: ___android-logo-mask.png
I/System.out: ___android-logo-shine.png
I/System.out: sounds
I/System.out: ___bootanim0.raw
I/System.out: ___bootanim1.raw
I/System.out: webkit
I/System.out: ___android-weberror.png
I/System.out: ___hyph_en_US.dic
I/System.out: ___incognito_mode_start_page.html
I/System.out: ___missingImage.png
I/System.out: ___nullPlugin.png
I/System.out: ___play.png
I/System.out: ___textAreaResizeCorner.png
I/System.out: ___togglePlugin.png
I/System.out: ___youtube.html
I/System.out: ___youtube.png
因篇幅问题不能全部显示,请点此查看更多更全内容