Java to write a. txt file, to implement several ways to wrap:
1. Use the escape character "\ r \ n" in Java:
Java code
1. String str= "AAA";
2. str+= "\ r \ n";
So there's a line of change behind Str.
Note: The order of \r,\n can not be exchanged, otherwise can not achieve the effect of line wrapping.
2.BufferedWriter newline () method:
Java code
1. FileOutputStream fos=new fileoutputstream ("C;\\11.txt");
2. BufferedWriter bw=new bufferedwriter (FOS);
3. Bw.write ("Hello");
4. Bw.newline ();
5. Bw.write ("Java");
6. W.newline ();
3. Use the System.getproperty () method:
Java code
1. String str = "AAA" +system.getproperty ("Line.separator");
As far as I know, there should be no common line breaks in Windows and Linux/unix platforms. For commonly used systems, you can use the following escape characters to implement line breaks:
Text file newline characters under Windows: \ r \ n
Text file newline characters under Linux/unix: \ r
Text file line feed under Mac: \ n