0

伙计们,我在 sdcard 中有一个文本文件,我需要阅读该文件。

下面是我读取文件的代码:

 File f = new File(Environment.getExternalStorageDirectory()+"/f1.txt");
       fileIS = new FileInputStream(f);
            BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));
           String readString = new String(); 
           //just reading each line and pass it on the debugger
           while((readString = buf.readLine())!= null){
              textdata.setText(readString);
              Log.d("line: ", readString);
           }
        } catch (FileNotFoundException e) {
           e.printStackTrace();
        } catch (IOException e){
           e.printStackTrace();
        }

但我需要动态地从 sdcard 读取文件。

在这里,我给了它f1.txt

4

1 回答 1

3

试试这个:

File f = new File(Environment.getExternalStorageDirectory().toString() + "/audio");
if (f.isDirectory())
{
    String files[] = f.list();
    for (int i = 0; i < files.length; i++)
    {
        Log.d("", files[i]);
    }
}
于 2012-03-01T12:41:38.967 回答