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();
}