问题
Guys i have a text file in sdcard i need to read that file.
Below is my code to read files:
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();
}
But i need to read files from sdcard dynamically.
here i have given it as f1.txt
回答1:
Try this:
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]);
}
}
来源:https://stackoverflow.com/questions/9516335/dynamically-read-files-from-sdcard