【发布时间】:2014-07-30 04:27:44
【问题描述】:
我以这种方式评估其中有子文件夹和文件..
如图所示 ..assest->www ->js 或 cs 文件夹..then 文件
assest
|
|__www
|
|___js
| |
| |__a.js
|
|____cs
| |
| |__a.css
|
|____index.html
我需要打印所有文件名..我们可以打印那个文件名
我做了这个功能但不起作用..
package com.mobilecem.atms;
import java.io.IOException;
import android.content.Context;
import android.util.Log;
public class GlobalFunction {
public static boolean listAssetFiles(String path,Context context) {
String [] list;
try {
list = context.getAssets().list(path);
if (list.length > 0) {
// This is a folder
for (String file : list) {
if (!listAssetFiles(path + "/" + file, context))
return false;
}
} else {
Log.d("File Name", "file present");
// This is a file
// TODO: add file name to an array list
}
}catch (IOException e) {
return false;
}
return true;
}
}
这样打电话
GlobalFunction.listAssetFiles("", aaa.this);
结果: 列表有:index.html、a.js、css
评论
【问题讨论】:
-
使用 AssetManager.list(String path) 获取给定路径下的所有文件
-
我们可以不做一个通用函数意味着它给assest文件夹中的所有文件名
-
我没明白,请你解释一下
-
@saleeh93 我只想要数组中assest文件夹中存在的所有文件名。正如我所说,在我的assest文件夹中有www文件夹然后文件夹中有js和cs文件夹有文件名称为 a.js 和 a.css。但在 www 中有 html 文件。我需要打印文件
-
我需要获取文件夹中存在的所有文件名
标签: android