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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:09:32+00:00 2026-05-22T20:09:32+00:00

I am reading a file via the BufferedReader String filename = … br =

  • 0

I am reading a file via the BufferedReader

String filename = ...
br = new BufferedReader( new FileInputStream(filename));
while (true) {
   String s = br.readLine();
   if (s == null) break;
   ...
}

I need to know if the lines are separated by ‘\n’ or ‘\r\n’
is there way I can find out ?

I don’t want to open the FileInputStream so to scan it initially.
Ideally I would like to ask the BufferedReader since it must know.

I am happy to override the BufferedReader to hack it but I really don’t want to open the filestream twice.

Thanks,

Note: the current line separator (returned by System.getProperty(“line.separator”) ) can not be used as the file could have been written by another app on another operating system.

  • 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-22T20:09:32+00:00Added an answer on May 22, 2026 at 8:09 pm

    After reading the java docs (I confess to being a pythonista), it seems that there isn’t a clean way to determine the line-end encoding used in a specific file.

    The best thing I can recommended is that you use BufferedReader.read() and iterate over every character in the file. Something like this:

    String filename = ...
    br = new BufferedReader( new FileInputStream(filename));
    while (true) {
       String l = "";
       Char c = " ";
       while (true){
            c = br.read();
            if not c == "\n"{
                // do stuff, not sure what you want with the endl encoding
                // break to return endl-free line
            }
            if not c == "\r"{
                // do stuff, not sure what you want with the endl encoding
                // break to return endl-free line
                Char ctwo = ' '
                ctwo = br.read();
                if ctwo == "\n"{
                    // do extra stuff since you know that you've got a \r\n
                }
            }
            else{
                l = l + c;
            }
       if (l == null) break;
       ...
       l = "";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With the following file reading code: using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read,
I'm reading a file using bufferedreader, so lets say i have line = br.readLine();
I'm reading a text file via CGI in, in perl, and noticing that when
i am reading in a binary file via the usual c++/STL/iostream syntax. i am
I'm reading Windows via c/c++ . And I just wonder a large file can
While implementing XML file reading/writing in my application I saw that when I call
I'm reading from an image file via OpenImageFileDialog , which accepts both .ico and
I'm reading a file in via apache.commons.FtpClient. This works fine 99.9% of the time
I am reading an external log file via xslt, and i want to find
I am reading in files via File.ReadAllText into a stringbuilder. I am doing some

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.