1. If you use a stream to write to a file line by line, you can replace FileWriter with PrintWriter, and then call the println() method of PrintWriter.
2.
Copy the code code as follows:
byte fileContent[] = getJTextArea().getText().replaceAll("/n", "/r/n").getBytes();//This is mainly to implement newline operation in Windows
3.
Copy the 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. Just insert the corresponding line breaks according to your respective systems:
Copy the code code as follows:
Text file newline character under windows:/r/n
Text file newline character under linux/unix:/r
Line break character in text files under Mac:/n