Home:ALL Converter>How to save newlines in file as LF (Unix convention)?

How to save newlines in file as LF (Unix convention)?

Ask Time:2015-10-17T15:02:51         Author:DarioBB

Json Formatter

I want to save my files as UTF-8 but newlines must not be done with CRLF (Windows convention), but as LF (Unix convetion). How to I do that?

Is it just enough to write "\n" at the end of the line, like this:

String data = "";
data += "My text line 1\n";
data += "My text line 2\n";

?

My file is saved properly so that every line is in it's row and that is good. How do I know is that Windows or Linux convention?

If this information is needed for my question, I'm saving my file with this:

new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF-8"));

But how do I know if my newlines are saved as LF and not as CRLF ?

Author:DarioBB,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/33183849/how-to-save-newlines-in-file-as-lf-unix-convention
Henry :

Yes this works. The file will contain just LF as line separator. To verify, open the file with your favorite hex editor.",
2015-10-17T07:10:37
yy