C#操作文件之 按行写入文件实例

下面是利用C#按行写入文件的操作:

 

            FileInfo finfo  =   new  FileInfo( " D:/result.dat " );
            
if  ( ! finfo.Exists)
            {
                finfo.Create();
            }
            
else
            {
                finfo.Delete();
                finfo.Create();
            }

            StreamWriter  sw 
=  finfo.AppendText();

            
for  ( int  i  =   0 ; i  <   100 ; i ++ )
            {
                
string  strValue  =   string .Format( " D{0:D5} " , i);
                sw.WriteLine(strValue);
            }
            sw.Close();

                   

你可能感兴趣的:(程序设计)