将写入的内容在文本文件中换行

hdb315871 2005-12-16 08:56:38
请各位帮我一下,怎样用FileWriter, 将我们的字符串写在文本文件中,在文本文件中进行换行呢?
我不知道怎样将写入的内容在文本文件中换行?
...全文
231 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
f_acme 2005-12-18
  • 打赏
  • 举报
回复
自己加个回车就得
newman0708 2005-12-18
  • 打赏
  • 举报
回复
53.字符串的回车
String s="hi newman"+"\r\n";加入了回车换行
beermonkey 2005-12-16
  • 打赏
  • 举报
回复
把这句out.write(32);改成out.write("\r\n");
hdb315871 2005-12-16
  • 打赏
  • 举报
回复
package studypack;
import java.io.*;
public class witeTxt
{

/**
* @param args
*/
public static void main(String[] args)
{
File file=new File("c:\\out.txt");
try
{
FileWriter out=new FileWriter(file);
String str1="www.csdn.com";
String str2="www.sina.com";
String str3=new StringBuffer().append("\"").append(str1).append("\"").toString();

String str4=new StringBuffer().append("\"").append(str2).append("\"").toString();
out.write(str3);
out.write(32);
out.write(str4);
out.close();
}
catch(Exception e)
{
e.getMessage();
}
try
{
FileReader in=new FileReader(file);
char buf[]=new char[1024];
int len=in.read(buf);
System.out.println(new String(buf,0,len));
}
catch(Exception e)
{
e.getMessage();
}
}

}


我现在要想在out.txt中,
将写入是内容变成这样:
www.csdn.com
www.sina.com
两行;怎么做啊?
小兽 2005-12-16
  • 打赏
  • 举报
回复
write的时候加上"\r\n"就好了``

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧