在文件续写中,\n和\r的区别?
- import java.io.FileWriter;
- import java.io.IOException;
- public class day18_9 {
- public static void main(String[] args) throws IOException {
- FileWriter fw = new FileWriter("demo3.txt", true);
-
- fw.write("hjhjhjjjj333\r\n");
- fw.write("hjhjhjjjj333\r\n");
- fw.write("hjhjhjjjj333\r\n");
- fw.close();
- }
- }
复制代码 这是正确的代码,可以打印出这个效果:
但是如果这样代码这样写:- import java.io.FileWriter;
- import java.io.IOException;
- public class day18_9 {
- public static void main(String[] args) throws IOException {
- FileWriter fw = new FileWriter("demo3.txt", true);
- fw.write("hjhjhjjjj333\n\r");
- fw.write("hjhjhjjjj333\n\r");
- fw.write("hjhjhjjjj333\n\r");
- fw.close();
- }
- }
复制代码 结果却是这样:
\n \r区别在哪里?单独使用fw.write("hjhjhjjjj333\r");和fw.write("hjhjhjjjj333\n");的结果又怎么解释?
|