While developing GUI with Java FX , I seem to get different results with System.getProperty("line.separator"); and "\n" during writing to a file or getting data from internet. What basically is the difference ?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
on the Windows platform, System.getProperty("line.separator") is "\r\n", "\n" (Linux and MacOS X), "\r" (MacOS 9 and older)
«\n» is the line separator for most operating systems such as Linux/Unix. To ensure the compatibility with any operating system, query this value with System.getproperty
System.getProperty("line.separator")
is platform dependent:Whereas "\n" is only "\n".
System.getProperty("line.separator")
returns the OS dependent line separator.On Windows it returns
"\r\n"
, on Unix"\n"
. So if you want to generate a file with line endings for the current operating systems useSystem.getProperty("line.separator")
or write using aPrintWriter
.