开发者

Store .txt filenames in array on Android

开发者 https://www.devze.com 2022-12-27 05:37 出处:网络
I would like to store only .txt filenames from a specific dir (let\'s say: /sdcard/docs/) into an String array.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消