Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9146021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:39:26+00:00 2026-06-17T10:39:26+00:00

I am using the following code to list down all the files present on

  • 0

I am using the following code to list down all the files present on the SD card. However I just want to list down all the text files can some body tell me how to add a file filter. Similarly I need to fetch the image files as well. Following is my code:

public ArrayList<String> GetFiles(String DirectoryPath) {
    ArrayList<String> MyFiles = new ArrayList<String>();
    File f = new File(DirectoryPath);

    f.mkdirs();
    File[] files = f.listFiles();
    if (files.length == 0)
        return null;
    else {
        for (int i=0; i<files.length; i++) 
            MyFiles.add(files[i].getName());
    }

    return MyFiles;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:39:28+00:00Added an answer on June 17, 2026 at 10:39 am

    Use .endsWith() method from Java String Class to check File Extension from file path.

    Method:

    public boolean endsWith(String suffix)
    

    Your Code something like,

    private List<String> ReadSDCard()
    {
         //It have to be matched with the directory in SDCard
         File f = new File("your path");
    
         File[] files=f.listFiles();
    
         for(int i=0; i<files.length; i++)
         {
          File file = files[i];
          /*It's assumed that all file in the path are in supported type*/
          String filePath = file.getPath();
          if(filePath.endsWith(".txt")) // Condition to check .txt file extension
          tFileList.add(filePath);
         }
     return tFileList;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using following code I try to get updated list of checkbuttons' corresponding text values,
I'm using the following code to get a list of all installed apps on
Using the following code, I'm retrieving a list of Integers from a DB and
I'm using the following code to download a pdf from a list of pdfs
I am using the following code to remove a attribute from session List<User> l=(List<User>)
I get the error list iterator not dereferencable when using the following code: bool
I'm using the following code to UPDATE certain records from the db: IList<Item> list;
In following code the issue is, that I cannot test dao.add() without using dao.list().size()
I am using the following well-known CSS code to get a drop down menu
I have the following code that populates a Drop Down List and auto submits

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.