简体   繁体   中英

How to read only text file from sdcard in android?

HI...

I am New To Android, My requirement is to display Total SDcard files in Listview , in that i want to read only TextFiles. Can anyone HelpMe.... Thanks in advance...

You should check out FilenameFilter .

Something like this:

FilenameFilter filter = new FilenameFilter() {          
    @Override
    public boolean accept(File dir, String filename) {
        return (filename.endsWith(".txt"));
    }
};

And:

String[] list = dir.list(filter);

There you go! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM