Dynamically read files with Sdcard

Guys, I have a text file on an SD card, I need to read this file.

Below is my code for reading 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 dynamically read files from the SDK.

here i gave it as f1.txt

0
source share
1 answer

Try the following:

 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]); } } 
+3
source

Source: https://habr.com/ru/post/1502767/


All Articles