无法获取Android asset目录中的文件
我正在尝试查找位于资产中的文件。我在 eclipse android 项目中有 .txt、.gif 和 .db 文件,但在运行以下代码时不显示:
AssetManager am = getAssets();
try {
String list[] = am.list("/");
I=0;
Str="";
while (list[] != null) {
Str=Str+"\r\n"+list[I];
I++;
}
}
catch(exception e){
}
我得到此列表:
AndroidManifest.xml
META-INF
assets
classes.dex
com
res
resources.arsc
此列表不包含资产中的任何文件。
项目属性当前设置为在构建路径中不包含资产文件夹。当我在构建路径中包含资产文件夹时,它会为我提供与第一个文件相同的列表,其中包含“..”。
我尝试将第三行中的“/”更改为“/assets/”,但没有返回任何内容。
在 Android 2.3.1 和 Android 2.1-update1 之间更改 Android 项目构建目标似乎没有效果。
项目属性中是否有需要将资产中的文件包含在构建中的设置?使用 AssetManager 的资产目录是否有不同的名称?
I am trying to find files located in assets. I have .txt, .gif, and .db files that are there in an eclipse android project but do not display when I run the following code:
AssetManager am = getAssets();
try {
String list[] = am.list("/");
I=0;
Str="";
while (list[] != null) {
Str=Str+"\r\n"+list[I];
I++;
}
}
catch(exception e){
}
I get this list:
AndroidManifest.xml
META-INF
assets
classes.dex
com
res
resources.arsc
This list does not include any of the files in assets.
Project properties is currently set to not include assets folder in the build path. When I do include the assets folder in the build path, it gives me the same list with ".." as the first file.
I have tried changing "/" in the third line to "/assets/" but get nothing returned.
Changing the Android Project Build Target between Android 2.3.1 and Android 2.1-update1 appears to have no effect.
Is there a setting in the project properties that is required for files in assets to be included in the build? Is there a different name for the assets directory using AssetManager?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
list() 采用资产内的相对路径。在您的情况下,您似乎需要传递一个空字符串 am.list("")
list() takes a relative path within the assets. Seems in your case you need to pass an empty string, am.list("")