The text area of JTextArea in Java Swing implements several methods for saving a new line to a file
- 2020-04-01 03:30:09
- OfStack
1. If you are writing line by line to a file as a stream, replace the FileWriter with the PrintWriter, and then call the PrintWriter println() method.
2.
byte fileContent[] = getJTextArea().getText().replaceAll("n", "rn").getBytes();//The main purpose here is to implement the newline operation
in Windows
3.
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 < br / >
fw.write(10);//Write n < br / >
}else{
fw.write(str.charAt(i));
}
}
fw.close();
4. Just insert the corresponding newline character according to the respective system:
windows The following text file newline character :rn
linux/unix The following text file newline character :r
Mac The following text file newline character :n