2

java.io.BufferedReader.readLine() returns us a "String containing the contents of the line, not including any line-termination characters". Is there any reader that will give us information about encountered line terminator?

Of course, we can just read sign by sign - but I wanted to know if there is a ready class/method for that?

PastorPL
  • 968
  • 3
  • 17
  • 36
  • Do you just want to look for `\n`, `\r` and `\r\n` (the only line separators that BufferedReader recognizes)? Or are you also interested in all the other Unicode line separators that java.util.Scanner also recognizes in addition to the above? – DodgyCodeException Oct 16 '18 at 13:51
  • For me `\n`, `\r` and `\r\n` will be enough. But if you could be so kind, you can share all the options :) – PastorPL Oct 16 '18 at 14:02
  • Scanner considers as line separator anything matching `"\r\n|[\n\r\u2028\u2029\u0085]"`. But if the traditional ASCII line separators are enough, I would probably derive a class from `BufferedReader` and override `readLine()`, as I couldn't find any ready-made third-party libs that do that. To avoid surprises, I would make `readLine()` do the same as BufferedReader.readLine() but also have a new method `String lastLineSeparator()` that returns the line separator that ended the last call of readLine(). – DodgyCodeException Oct 16 '18 at 14:06

0 Answers0