Search code examples
javabufferedreaderlinefeed

Detect \n in BufferedReader stream


I have a string that looks something like this:

"foobar\n"

I read this string using a BufferedReader. I need to be able to detect whether or not there is a new line present. I was using readLine, but I switched to read so I could grab the \n but no luck.


Solution

  • I tried this and it works:

    while((charT = reader.read()) != -1) {
    if(charT != '\n')
    System.out.println("Carriage Return!");
    }