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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:37:57+00:00 2026-05-26T20:37:57+00:00

Okay, I tried everything but I can’t find answer. My data reader skips empty

  • 0

Okay, I tried everything but I can’t find answer. My data reader skips empty next line while reading from a txt file.
It is supposed to strip all the comments from the txt file and print rest of the data as it is. My reader does strip the comments & prints the data but it skips the empty new lines..

MyDataReader.java

public String readLine()
{
    String buf = new String();
String readStr = new String();

int end = 0;
int done = 0;

try
{
    // checks if line extraction is done and marker has non null value
    while (done != 1 && marker != null)
    {
    readStr = theReader.readLine(); // Reads the line from standard input

    if (readStr != null)
    {
        /* If the first character of line isnt marker */
        if (readStr.length() > 0)
        {
            if (!readStr.substring(0, 1).equalsIgnoreCase(marker))
        {
            end = readStr.indexOf(marker);   // checks if marker exists in the string or not
            if (end > 0)
            buf = readStr.substring(0, end);
            else
            buf = readStr;

            done = 1;   // String extraction is done
         }
        }
    }
    else
    {
            buf = null;
        done = 1;
    }
    }
}
// catches the exception
catch (Exception e)
{
    buf = null;
    System.out.println(e);
}

return buf;
}

TestMyDataReader.java

String myStr = new String();

  myStr = _mdr.readLine();

  while (myStr != null)
  {
      //System.out.println("Original String : " + myStr);
      System.out.println(myStr);
      myStr = _mdr.readLine();
  }
  • 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-05-26T20:37:57+00:00Added an answer on May 26, 2026 at 8:37 pm

    if (readStr.length() > 0)

    That’s the line of code that is skipping empty lines.

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

Sidebar

Related Questions

I've tried looking on stackoverflow, but can't quite find the same issue as me
Okay, I've seen but haven't programmed in C# before. You can assume I'm competent
I want a simple MessageBox for ASP.Net, but everything I tried didn't work and
Sorry, I'm probably missing something simple here, but I feel like I've tried everything.
Okay, I've tried using Google-sensei and searching around on this website, and while I've
Okay, I've tried about 8 different ways to get a key event into my
Okay, I'm fairly new to R and I've tried to search the documentation for
Okay, this is starting to drive me a little bit nuts. I've tried several
Okay so im working on this php image upload system but for some reason
Okay, so this probably sounds terribly nefarious, but I need such capabilities for my

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.