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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:53:57+00:00 2026-06-18T15:53:57+00:00

I have a file and I want to read in the string on each

  • 0

I have a file and I want to read in the string on each line. If the line does not end in CRLF (\r\n), I want to to print something. I made this file by redirecting output from print commands similar to the following.

System.out.println("Test\r\n");

But when I read this line in from the file using buffered reader, it doesn’t seem like it catches the CRLF.

I use the following to detect the crlf (where inputline is the line that has been read in).

if(inputline.indexOf("\r\n")<0)

It never detects the \r\n. How can I remedy this? Is this an issue with buffered reader?

  • 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-18T15:53:58+00:00Added an answer on June 18, 2026 at 3:53 pm

    readLine

    public String readLine()
    throws IOException

    Read a line of text. A line is considered to be terminated by any one of a line feed (‘\n’), a carriage return (‘\r’), or a carriage return followed immediately by a linefeed.

    Returns:

    A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached

    from http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html

    Thus you may need to write some of your own code (or take this, borrowed from http://www.coderanch.com/t/276442//java/Reading-file-byte-array)

    private byte[] toByteArray(File file) throws FileNotFoundException, IOException{  
        int length = (int) file.length();  
        byte[] array = new byte[length];  
        InputStream in = new FileInputStream(file);  
        int offset = 0;  
        while (offset < length) {  
            offset += in.read(array, offset, (length - offset));  
        }  
        in.close();  
        return array;  
        }
    

    This will give you all the bytes – nothing stripped. Knock yourself out looking for \r\n…

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

Sidebar

Related Questions

Suppose I have an output file that I want to read and each line
I have KML file and I want to read this file and to do
I have an excel file and I want to read each column and create
I have one binary file and I want to read this file like first
I have a .txt file having some text. I want to read this file
My code should read file and store each line(each record) into a String array.
I have a file with multiple strings, each string on a separate line. All
I have a file which i will read it line by line. Split each
In a file I have pair of names on each line. Like this: John
I have a text file that I want to read line by line and

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.