简体   繁体   中英

newLine() and CR/LF comparison

Is the BufferedWriter.newLine() method in Java equals CR/LF ? What's actually inside of that method?

No.

BufferedWriter.newLine() writes a line separator. This is not necessarily "\\r\\n" . Quoting the Javadoc :

The line separator string is defined by the system property line.separator , and is not necessarily a single newline ( '\\n' ) character.

The system property line.separator contains the line separator of the current OS by default.

Inside of that method is:

 write(lineSeparator);

Where lineSeparator is an attribute of the BufferedWriter class that holds the System.getProperty("line.separator"); value in the moment the buffer was opened.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM