随风而行

^o^ 格言:相信没有做不到的事情,只有想不到的事情.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

StreamReader & StreamWriter用法

Posted on 2009-02-23 10:55  随风而行  阅读(1135)  评论(2)    收藏  举报
public void wirte()
    {
        try
        {
            StreamReader sr = new StreamReader("c:\\Variables.txt");
            string content = sr.ReadToEnd();
            sr.Close();

            StreamWriter sw = new StreamWriter("c:\\Variables.txt", false, Encoding.Unicode);
            string NextLine = "This is the appended line.";

            sw.Write(content + ControlChars.NewLine + NextLine);
            sw.Close();
        }
        catch(Exception ex)
        {
            Response.Write(ex.Message);
        }
        finally
        {
        }

    }