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 8464461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:45:10+00:00 2026-06-10T14:45:10+00:00

I am currently searching the sd card for any file types .csv and .txt

  • 0

I am currently searching the sd card for any file types .csv and .txt. I am displaying the lines of these files as a toast. I’d like to now display only the lines that contain defined keywords. It seems to me that I should use the RuleBasedCollator but I am not sure about how to implement it.

Is that the correct way I should be doing this or is there another, better solution?

Thanks

Code (I’ve commented on the second if, where my question is):

    private void conductScan() {

    File[] file = Environment.getExternalStorageDirectory().listFiles();  


    for (File f : file)
    {
       if (f.isFile() && f.getPath().endsWith(".xml") || f.getPath().endsWith(".txt")) {
           StringBuilder text = new StringBuilder();
           try {
               BufferedReader br = new BufferedReader(new FileReader(f));
               String line;
               while ((line = br.readLine()) != null) {
                   text.append(line);
                   text.append('\n');
                   if (line ) {  //here I want to define if line contains "test" then show the toast"
                       Toast.makeText(getApplicationContext(),line,Toast.LENGTH_LONG).show();
                       } else {
                           Toast.makeText(getApplicationContext(),"No keyewords found",Toast.LENGTH_LONG).show();
                       }
                   }
               }
           catch (IOException e) {
               Toast.makeText(getApplicationContext(),"Error reading file!",Toast.LENGTH_LONG).show();
           }
               String [] mStrings=text.toString().split("\n");
       }

    }
}
  • 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-10T14:45:12+00:00Added an answer on June 10, 2026 at 2:45 pm

    To check if the line contains a substring you could use the:

    public boolean contains(CharSequence s)

    of the String class.

    Not sure if that was the problem. The problem with this would be, that your loop will iterate through the lines really fast, and you won’t be able to see the messages.

    You could print those lines to the Log or into another text file to analize it later.

    EDIT:

    You could change this part:

    while ((line = br.readLine()) != null) 
    {
        //be careful! with this, you will add all the lines of
        //the currently processed file to a locally created 
        //StringBuilder object. Is this really what you want?
        text.append(line);
        text.append('\n');
    
        //here if line contains "test" you can do whatever you want with it.
        if (line.contains("test")) 
        {
            //do something with it
        }
        else
        {
            //no "test" keyword in the current line
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, CTRL + P (Goto Anything) shortcut searching the file only in the current
I've searched Google for awhile now, doesn't seem like I am correctly searching it
I understand how to search through a txt file searching for a value (or
I'm currently searching for physical size limitation of a DTSX file. We lose someting
Our company currently implementing TSA (Time Stamp Authority) service. And now we are searching
I'm currently searching for replacement for Spring IoC container. I like Spring, but it
I'm currently searching for ways I can best display results like a report coupled
I am currently searching my database with a query (using JDBC) like this: ...
I'm currently using FindFirstFile, FindNextFile API to recursively iterate through directories for searching files
I am currently searching through an HTML page for a specific link, at the

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.