简体   繁体   English

从资产文件夹获取txt文件的名称到列表中

[英]get the names of txt files from assets folder into a list

I'm trying to get a list of the name of txt files stored in my assets folder but when i call 我正在尝试获取存储在资产文件夹中的txt文件名称的列表,但是当我打电话时

String[] files = assetManager.list("/assets");

i get an exception 我有一个例外

01-13 15:48:44.819: E/AndroidRuntime(6754): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.readd/com.example.readd.MainActivity}: 

i suppose i have and error with the parameter "/assets" in list("/assets")., but dont have idea how to solve it. 我想我在list(“ / assets”)中有参数“ / assets”并出错了,但是我不知道如何解决它。

EDIT in my assets folder i got just raw files without subfolders 在我的资产文件夹中编辑 ,我得到的只是原始文件,没有子文件夹

text1.txt text1.txt

text2.txt text2.txt

text3.txt text3.txt

i've try also assetManager.list(""); 我也尝试了assetManager.list(“”); but when i try to set a txtView with the name of the(lets say) first file tt.setText(files[0]);, it give's me images as a result, and i dont have file like that in my assets 但是当我尝试使用第一个文件tt.setText(files [0]);的名称设置txtView时,结果是给我图像,而我的资产中没有这样的文件

EDIT2 EDIT2

            AssetManager assetManager = getApplicationContext().getAssets();
    try {

        String[] files = assetManager.list("");

        InputStream stream = getAssets().open("text1.txt");

        tt.setText(files[0]);//here i get images(as String not real images) as result
        }

it should be 它应该是

String[] files = assetManager.list("");

if you want to get what's inside a subfolder pass the name of the subfolder: 如果要获取子文件夹中的内容,请传递子文件夹的名称:

String[] files = assetManager.list("mySubFolder");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM