I have a Java program which generates a text file on a UNIX server. This text file is then sent to a customer's machine using other systems where it is supposed to be opened in notepad on Windows. As we are well aware that notepad will not be able to find a new line as it uses Windows CR LF.
I am using
System.getProperty("line.separator");
Is there another way of acheiving platform independece so that a file generated on UNIX can be displayed in Windows notepad with the proper formatting like changing some UNIX property for new line?
Notepad is a pre-requisite, hence changing that is not possible.
In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF. Adding a new line in Java is as simple as including “\n” , “\r”, or “\r\n” at the end of our string.
The lineSeparator() is a built-in method in Java which returns the system-dependent line separator string. It always returns the same value – the initial value of the system property line. separator. Syntax: public static String lineSeparator()
Since Java 7 System.lineSeparator()
..
Java APIs keep changing with time. Writing new line character in Java that works across different OS could be achieved with System.lineSeparator()
API which has been there since Java 7. check this,
System.lineSeperator()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With