下面代码写入文件为什么后面会多出几行代码。c#文件
rotected void Button1_Click1(object sender, EventArgs e)
{
FileStream fs = new FileStream(Server.MapPath("htmlTemplate/1方法.htm"), FileMode.Open, FileAccess.Read);
StreamReader m_streamReader = new StreamReader(fs, Encoding.GetEncoding("utf-8"));
m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
this.txtContext.Text = "";
string strLine = m_streamReader.ReadLine();
while (strLine != null)
{
this.txtContext.Text += strLine;
strLine = m_streamReader.ReadLine();
}
m_streamReader.Close(); }
protected void Button2_Click1(object sender, EventArgs e)
{
FileStream fs = new FileStream(Server.MapPath("htmlTemplate/1方法.htm"), FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs, Encoding.GetEncoding("utf-8"));
m_streamWriter.BaseStream.Seek(0, SeekOrigin.Begin);
m_streamWriter.WriteLine(txtContext.Text);
m_streamWriter.Flush();
m_streamWriter.Close();
}html模版
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<table id="tableTemp" class="tableTemp" cellpadding="2px" cellspacing="0" style="border-collapse: collapse"
border="1px" bordercolor="#CCCCCC">
<tbody>
<tr>
<th>
计划1
</th>
<th>
计划2
</th>
<th>
计划3
</th>
<th>
计划4
</th>
</tr>
<tr>
<td>
<input class="input" type="text">
</td>
<td>
<input class="input" type="text">
</td>
<td>
<input class="input" type="text">
</td>
<td>
<input class="input" type="text">
</td>
</tr>
</tbody>
</table>
</body>
</html>
rotected void Button1_Click1(object sender, EventArgs e)
{
FileStream fs = new FileStream(Server.MapPath("htmlTemplate/1方法.htm"), FileMode.Open, FileAccess.Read);
StreamReader m_streamReader = new StreamReader(fs, Encoding.GetEncoding("utf-8"));
m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
this.txtContext.Text = "";
string strLine = m_streamReader.ReadLine();
while (strLine != null)
{
this.txtContext.Text += strLine;
strLine = m_streamReader.ReadLine();
}
m_streamReader.Close(); }
protected void Button2_Click1(object sender, EventArgs e)
{
FileStream fs = new FileStream(Server.MapPath("htmlTemplate/1方法.htm"), FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs, Encoding.GetEncoding("utf-8"));
m_streamWriter.BaseStream.Seek(0, SeekOrigin.Begin);
m_streamWriter.WriteLine(txtContext.Text);
m_streamWriter.Flush();
m_streamWriter.Close();
}html模版
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<table id="tableTemp" class="tableTemp" cellpadding="2px" cellspacing="0" style="border-collapse: collapse"
border="1px" bordercolor="#CCCCCC">
<tbody>
<tr>
<th>
计划1
</th>
<th>
计划2
</th>
<th>
计划3
</th>
<th>
计划4
</th>
</tr>
<tr>
<td>
<input class="input" type="text">
</td>
<td>
<input class="input" type="text">
</td>
<td>
<input class="input" type="text">
</td>
<td>
<input class="input" type="text">
</td>
</tr>
</tbody>
</table>
</body>
</html>
while (strLine != null) 意思是把这句替换