Store .txt filenames in array on Android
I would like to store only .txt
filenames from a specific dir (let's say: /sdcard/docs/
) into an String
array.
Example:
In /sdcard/docs/
there are 5 files: foo.txt
, bar.jpg
, foofoo.txt
, loool.png
and foobar.txt
. I would like to get array with contents: "foo.txt", "foofoo.txt", "foobar.txt"
How开发者_Go百科 could I do it?
List all files:
https://developer.android.com/reference/java/io/File.html#list%28%29
or
List with filter:
https://developer.android.com/reference/java/io/File.html#list%28java.io.FilenameFilter%29
Just pass your path to the File constructor, and call one of the above methods on it.
精彩评论