java中写.txt文件,实现换行的几种方法: 
1.使用java中的转义符"/r/n": 

  String str="aaa";
   str+="/r/n";
  

 这样在str后面就有换行了. 
 注意:/r,/n的顺序是不能够对换的,否则不能实现换行的效果. 

2.BufferedWriter的newline()方法: 

   FileOutputStream fos=new FileOutputStream("c;//11.txt");
   BufferedWriter bw=new BufferedWriter(fos);
   bw.write("你好");
   bw.newline();
   bw.write("java");
  bw.newline(); 
 

3.使用System.getProperty()方法: 

   String str = "aaa"+System.getProperty("line.separator");
 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-08-24
  • 2021-05-18
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2021-04-19
相关资源
相似解决方案