c#中怎样用StreamWriter写数据?然后再用streamReader读出啊?
1个回答
2013-12-05
展开全部
写入/读出文本文件
public void Page_Load(Object src,EventArgs e)
{
StreamWriter rw = File.CreateText(Server.MapPath(".")+"\\myText.txt");
rw.WriteLine("test");
rw.WriteLine("test1");
rw.WriteLine("test2");
rw.Flush();
rw.Close();
}
打开文本文件
StreamReader sr = File.OpenText(Server.MapPath(".")+"\\myText.txt");
StringBuilder output = new StringBuilder();
string rl;
while((rl=sr.ReadLine())!=null)
{
output.Append(rl+"<br>");
}
lblFile.Text = output.ToString();
sr.Close();
public void Page_Load(Object src,EventArgs e)
{
StreamWriter rw = File.CreateText(Server.MapPath(".")+"\\myText.txt");
rw.WriteLine("test");
rw.WriteLine("test1");
rw.WriteLine("test2");
rw.Flush();
rw.Close();
}
打开文本文件
StreamReader sr = File.OpenText(Server.MapPath(".")+"\\myText.txt");
StringBuilder output = new StringBuilder();
string rl;
while((rl=sr.ReadLine())!=null)
{
output.Append(rl+"<br>");
}
lblFile.Text = output.ToString();
sr.Close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询