1. If you are writing to a file in a single line of flow, you can change the filewriter to PrintWriter, and then call the PrintWriter println () method.
2.
Copy Code code as follows:
byte filecontent[] = Getjtextarea (). GetText (). ReplaceAll ("\ n", "\ r \ n"). GetBytes ();//The main purpose of this is to implement line-wrapping operations in Windows
3.
Copy Code code as follows:
FileWriter fw=new FileWriter (file);
String Str=txt.gettext ();
for (int i=0;i<str.length (); i++) {
if (Str.charat (i) ==10) {
Fw.write (13);//write \ R
Fw.write (10);//write \ n
}else{
Fw.write (Str.charat (i));
}
}
Fw.close ();
4. As long as the corresponding line breaks are inserted according to their respective systems:
Copy Code code as follows:
Text file newline characters under Windows: \ r \ n
Text file newline characters under Linux/unix: \ r
Text file line feed under Mac: \ n