How do I get a platform independent newline in java? I can't use "\n" everywhere.
+36
A:
You can use
System.getProperty("line.separator");
to get the line separator
abahgat
2008-10-16 09:39:26
+12
A:
In addition to the line.separator property, if you are using java 1.5 or later and the String.format (or other formatting methods) you can use %n
as in
Calendar c = ...;
String s = String.format("Duke's Birthday: %1$tm %1$te,%1$tY%n", c);
//Note %n at end of line ^^
String s2 = String.format("Use %%n as a platform independent newline.%n");
// %% becomes % ^^
// and %n becomes newline ^^
See the Java 1.5 API for Formatter for more details.
Alex B
2008-10-16 18:45:40
+3
A:
If you're trying to write a newline to a file, you could simply use BufferedWriter's newLine() method.
Michael Myers
2008-10-16 18:49:15