How do I get a platform-dependent newline in Java? I can’t use "\n"
everywhere.
相关问题
- 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
This is also possible:
String.format("%n")
.Or
String.format("%n").intern()
to save some bytes.If you are writing to a file, using a
BufferedWriter
instance, use thenewLine()
method of that instance. It provides a platform-independent way to write the new line in a file.Avoid appending strings using String + String etc, use StringBuilder instead.
The commons-lang library has a constant field available called SystemUtils.LINE_SEPARATOR
You can use
to get the line separator
Java 7 now has a
System.lineSeparator()
method.