C#写文件代码

using System;
using System.IO;

public class TestWriteFile
{
    public static void Main(String[] args)
    {
        // Create a text file C:\temp\test.txt
        FileStream fs = new FileStream(@c:\temp\test.txt , FileMode.OpenOrCreate, FileAccess.Write);
        StreamWriter sw = new StreamWriter(fs);
        // Write to the file using StreamWriter class
        sw.BaseStream.Seek(0, SeekOrigin.End);
        sw.WriteLine( First Line );
        sw.WriteLine( Second Line);
        sw.Flush();
    }
}

posted on 2008-09-01 23:48  VictorShan  阅读(1544)  评论(0)    收藏  举报

导航