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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:33:09+00:00 2026-06-04T00:33:09+00:00

Below is my current function. It works fine and returns true if the lineToCompare

  • 0

Below is my current function. It works fine and returns true if the lineToCompare is found.

public static int checkrank(String lineToCompare){
    try{
        // Open the file that is the first 
        // command line parameter
        FileInputStream fstream = new FileInputStream("ranks.txt");

        // Get the object of DataInputStream
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));

        String strLine;
        //Read File Line By Line

        while ((strLine = br.readLine()) != null)   {
        //Compare the line with the line to compare (string)
        if(strLine.trim().compareTo(lineToCompare) == 0)
          return true;
        }

        //Close the input stream
        in.close();
    }catch (Exception e){//Catch exception if any
        System.err.println("Error: " + e.getMessage());
    }

    return false;

}

However, I need it to get the line AFTER the lineToCompare is found.

Here’s an example text file:

xXPwnageLolXx
1
SomethingTest
0
AnotherSomething
3

I need it to find the line of text (lineToCompare), then return the number AFTER the line found. How would I do this?

  • 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-04T00:33:10+00:00Added an answer on June 4, 2026 at 12:33 am
    while ((strLine = br.readLine()) != null)   {
        //Compare the line with the line to compare (string)
        if(strLine.trim().compareTo(lineToCompare) == 0) {
          //I found it!  Read the next line...
          final String lineAfter = br.readLine();
          return Integer.parseInt(lineAfter);    
        }
    }
    

    I’ve edited this snippet to include Dowards suggestion. The local variable is unnecessary, I’m just leaving it in for readability.

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

Sidebar

Related Questions

Im trying to generate a color gradient using ColdFusion. My current code below works
Below is my current code. And it is working fine, but I need the
i have rotating image in my webpage. link is below: http://equosinfotech.com/testdemo/test.html everything works fine
I have a simple bit of jQuery which displays the row below the current
I'm having trouble setting a custom back button. Below is the current code I'm
Below you will find my current vHost entry that I am using for a
My current LINQ query and example XML are below. What I'd like to do
Below I present you some code which has completely been butchered by me. $(.gig).hover(function()
Below is a fine piece of artwork that represents a WPF form with a
The code below scans through the current folder for word documents and then spits

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.