using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StreamWriter sw = File.CreateText(Server.MapPath (".")+"//hello.txt");
sw.WriteLine("你好:");
sw.WriteLine("欢迎学习Asp.Net");
sw.Flush();
sw.Close(); StreamReader sr = File.OpenText(Server.MapPath(".") + "//hello.txt");
//StringBuilder sb = new StringBuilder();//提高效率的方法 string s1; while ((s1 = sr.ReadLine()) != null)
{
//Response.Write(s1 + "<br>");//在这里可以正常输出两行文本
//sb.Append(s1+"</br>");//提高效率的方法
s1 += s1 + "<br>";//
}
// Response.Write(sb);
// Response.Write (s1);//放在这里居然什么也没输出,怎么回事???s1的值跑哪里去了?被谁吃了?!
sr.Close();
}
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StreamWriter sw = File.CreateText(Server.MapPath (".")+"//hello.txt");
sw.WriteLine("你好:");
sw.WriteLine("欢迎学习Asp.Net");
sw.Flush();
sw.Close(); StreamReader sr = File.OpenText(Server.MapPath(".") + "//hello.txt");
//StringBuilder sb = new StringBuilder();//提高效率的方法 string s1; while ((s1 = sr.ReadLine()) != null)
{
//Response.Write(s1 + "<br>");//在这里可以正常输出两行文本
//sb.Append(s1+"</br>");//提高效率的方法
s1 += s1 + "<br>";//
}
// Response.Write(sb);
// Response.Write (s1);//放在这里居然什么也没输出,怎么回事???s1的值跑哪里去了?被谁吃了?!
sr.Close();
}
}
退出循环的时候当然 null 了
string s1;
string s2 = string.Empty;
while ((s1 = sr.ReadLine()) != null)
{
s2 += s1 + "<br>";
} Response.Write (s2);