日期:2014-05-19  浏览次数:21112 次

为什么在写入文件的时候string的"\n"不起作用??
如题,下面代码中的\n写入文件中没有换行……
应该怎么弄才能使它换行呢??
怎么解决呢??
谢谢……

#region   Using   directives

using   System;
using   System.Collections.Generic;
using   System.Text;
using   System.IO;

#endregion

namespace   StreamWrite
{
      class   Program
      {
            static   void   Main(string[]   args)
            {
                  try
                  {
                        FileStream   aFile   =   new   FileStream( "Log.txt ",   FileMode.OpenOrCreate);
                        StreamWriter   sw   =   new   StreamWriter(aFile);

                        bool   truth   =   true;
                        //   Write   data   to   file
                        sw.WriteLine( "Hello   to   you. ");
                        sw.WriteLine( "It   is   now   {0}   and   things   are   \n\n\nlooking   good. ",
                  //\n   has   no   effect!!
                                                  DateTime.Now.ToLongDateString());
                        sw.Write( "More   than   that, ");
                        sw.Write( "   it 's   {0}   that   C#   is   fun. ",   truth);
                        sw.Close();
                  }
                  catch   (IOException   e)
                  {
                        Console.WriteLine( "An   IO   exception   has   been   thrown! ");
                        Console.WriteLine(e.ToString());
                        Console.ReadLine();
                        return;
                  }
            }
      }
}

------解决方案--------------------
\r\n
------解决方案--------------------
\n已经换行了...只不过某些Windows的应用程序不作为换行显示而已...历史遗留问题...