请各位帮我一下,怎样用FileWriter, 将我们的字符串写在文本文件中,在文本文件中进行换行呢?
我不知道怎样将写入的内容在文本文件中换行?

解决方案 »

  1.   

    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
    两行;怎么做啊?
      

  2.   

    把这句out.write(32);改成out.write("\r\n");
      

  3.   

    53.字符串的回车
    String s="hi newman"+"\r\n";加入了回车换行