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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:52:41+00:00 2026-06-10T21:52:41+00:00

I want to read a data stream and everytime it reads a certain word

  • 0

I want to read a data stream and everytime it reads a certain word or phrase I want the count to go up. The example I have below fails to count it. I tried looking for “echo percent” as well. All the bat file does is echo percent.

try { 
    String ls_str;
    String percent = "percent";
    Process ls_proc = Runtime.getRuntime().exec("c:\\temp\\percenttest.bat"); 
    // get its output (your input) stream    
    DataInputStream ls_in = new DataInputStream(ls_proc.getInputStream()); 
    while ((ls_str = ls_in.readLine()) != null ) { 
        System.out.println(ls_str);
        progressBar.setValue(progress);
        taskOutput.append(String.format(ls_str+"\n", progress));
        if (ls_str == percent)  {
            progress++;   
        } 
    }
} catch (IOException e1) { 
    System.out.println(e1.toString());                 
    e1.printStackTrace();
}

setProgress(Math.min(progress, 100));   
  • 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-10T21:52:43+00:00Added an answer on June 10, 2026 at 9:52 pm

    Don’t compare the Strings with ==, use the equals method.

    If you compare the Strings with ==, you’re checking to see if they’re the same String.

    If you compare them with equals, you’re checking whether or not their contents are the same.

    Instead of:

    if (ls_str == percent)

    Do this:

    if (ls_str.equals(percent))

    If you want to ignore case, you can do it like this:

    if (ls_str.equalsIgnoreCase(percent))


    EDIT

    Your String format is also messed up.

    Change:

    taskOutput.append(String.format(
    ls_str+"\n", progress));

    to:

    taskOutput.append(String.format(
    ls_str+"\n"), progress);

    Notice the parentheses change.


    Take a look at these for more explanations:

    Java String.equals versus ==

    http://www.java-samples.com/showtutorial.php?tutorialid=221

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a specific object with image data. And I want read/write images (in
Okay, so I want to have a generic method that can read data from
I have Uitable with data read from a AScii file. I want to select
I would like to read some data from a stream I have using std::getline
I want to read data records from a non-seekable stream in Ruby. I want
let's say we have 2 big list or stream of data and we want
I want to read a stream of GPS data and display the latitude and
I want to open a stream to a httpS URL and read the data.
Assume I have copied a byte buffer into a memory stream using this memoryStream.Read(data,
I want to read data stream or a key stroke from a secondary USB

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.