StreamReader、 StreamWriter

protected void Application_Start(Object sender, EventArgs e)
  {
    StreamReader rd = new StreamReader(Server.MapPath("counter.txt"));
    int nNum = int.Parse(rd.ReadLine());
    Application.Lock();
    Application["Counter"] = nNum;
    Application.UnLock();
    rd.Close();
  }

protected void Session_Start(Object sender, EventArgs e)
  {
    Application.Lock();
    Application["Counter"] = Convert.ToInt32(Application["Counter"])+1;
    Application.UnLock();
    //写入
    StreamWriter sw = new StreamWriter(Server.MapPath("counter.txt"),false);//false为不追加
    sw.WriteLine(Application["Counter"]);
    sw.Close();

  }

protected void Session_End(Object sender, EventArgs e)
  {
   //写入
   StreamWriter sw = new StreamWriter(Server.MapPath("counter.txt"),false);//false为不追加
   sw.WriteLine(Application["Counter"]);
   sw.Close();

  }

posted @ 2006-10-20 14:18  RobotTech  阅读(648)  评论(0编辑  收藏  举报