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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:36:26+00:00 2026-06-12T00:36:26+00:00

I have a program that reads in lines from a file (with two lines)

  • 0

I have a program that reads in lines from a file (with two lines) using a while loop (condition is bufferedReader.readLine()!=null), assigns myJSONObject a JSON read from the file, then I have an if statment (if(bufferedReader.readLine()!=null&&!bufferedReader.readline.matches(DELETE_REGEX)) and if that’s true (i.e. if the line we read is not null, and we don’t match a regex) then perform some function on the JSON which should append that new JSON to a file.

I have this in some try-catch blocks. It looks a little like so:

try{
    openFiles;
    while(buff.readLine()!=null){
          try {
              instatiateAndUseJSONParser;
              if(bufferedReader.readLine()!=null
                    &&!bufferedReader.readline.matches(DELETE_REGEX)) 
              {doSomeStuff;}
              else
              {continue;}
          } catch (AllTheExceptions e){e.printStackTrace}
     }
     closeFiles;
}catch(SomeMoreExceptions e){e.printStackTrace}

When I run this is gets to the iff statement, and then terminates with exit value:0 (program closed as normal)

Why is this? It doesn’t get anywhere near the ‘continue’ or a catch block.

If I remove the second line I get a NullPointerException due to line 50 of String Reader, but I’m not using StringReader (I’ve tried importing it, but eclipse yellow-underlines it and this changes nothing). When debugging, it pops up a tab for StringReader.<init>(String) line: 50 and just says ‘Source not found’.

I’m pretty new to Java, so I don’t really have a clue what’s happening. Any help would be appreciated in clearing this up.

Thanks!

  • 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-12T00:36:27+00:00Added an answer on June 12, 2026 at 12:36 am

    Every time readLine() is called, it reads a new line. You can thus read 3 lines per iteration in your current code. You should assign the result of the first call to a variable, and use this variable:

    String line = null;
    while ((line = buff.readLine()) !=null) {
        try {
            instatiateAndUseJSONParser;
            if (line.matches(DELETE_REGEX)) {
                doSomeStuff;
            }
        } 
        catch (AllTheExceptions e){
            throw new RuntimeException(e);
        }
    }
    

    You should also avoid swallowing exceptions.

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

Sidebar

Related Questions

I have a for loop that reads lines from an Excel file, checks them
I have a Java program that reads lines from text file. I want to
I have a program that reads data from a file line-by-line. I would like
I have a program that reads from a file that grabs 4 bytes from
I have a program that reads input from a file. I am trying to
I want to have a program that reads metadata from an MP3 file. My
I have a small Java program that reads list of IPs from text file
I have a program that load data from a file using std::ifstream and store
I have a program that reads a file, treat it and put the results
I have a program that reads one image file, makes some changes on that

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.