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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:52:19+00:00 2026-06-02T01:52:19+00:00

Good day, everyone. I’m using sableCC , and it takes as input a Reader

  • 0

Good day, everyone.

I’m using sableCC, and it takes as input a Reader object. For example this code works correctly:

compile (new StringReader ("print 1"));

Because StringReader returns -1 after the string is over:

StringReader sr = new StringReader("print 1");
while (sr.ready())
    System.out.println (sr.read());

Gives:

112
114
105
110
116
32
49
-1
... always -1

But when i write the same string into file “prog”, without any extra lines, or characters, And make a FileReader on it, the compiler breaks on an nonexistent second line, because instead of a -1 character, FileReader returns newline character:

FileReader fr = new FileReader( new File("prog"));
while (fr.ready())
    System.out.println (fr.read());

Gives:

112
114
105
110
116
32
49
10

What is the shortest way to get from a file reader the same behaviour as from StringReader, or may be SableCC allows a sideway?

  • 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-02T01:52:21+00:00Added an answer on June 2, 2026 at 1:52 am

    If the FileReader returns a new line character then that’s because there is a new line character in the file, even if your text editor doesn’t show it.

    Unfortunately some editors add a new empty line in text files automatically when saving. I think for example that emacs and gedit both do this. Try a different editor.

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

Sidebar

Related Questions

Good day everyone, I am building a page in ASP.NET, and using Master Pages
Good Day Everyone... Apparently, I'm not setting-up impersonation correctly for my WCF service. I
Good day everyone, this is one of those areas that is a little over
Good day everyone. I have a question about making and using derived classes of
Good day everyone! I am trying to understand how buffer overflow works. Right now,
Good day everyone I need to execute command on linux machine this command is
Good day everyone. This problem was part of another one which it as been
Good day everyone. I am working on a Firefox extension, and I want to
Good Day Everyone... I’m getting an unexpected WCF error complaining of Known Types which
Good day everyone. I have been having the same problem all day at work

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.