在 System.ArgumentException 中第一次偶然出现的“System.Windows.Forms.dll”类型的异常.
privatevoidbutton1_Click(objectsender,EventArgse){FileStreamfs=newFileStream("C:\file...
private void button1_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream("C:\file.txt", FileMode.Open, FileAccess.Read);
StreamReader sw = new StreamReader(fs);
//使用StreamReader类来读取文件
sw.BaseStream.Seek(0, SeekOrigin.Begin);
// 从数据流中读取每一行,直到文件的最后一行,并在richTextBox1中显示出内容
this.content.Text = "";
string strLine = sw.ReadLine();
while (strLine != null)
{
this.content.Text += strLine + "\n";
strLine = sw.ReadLine();
}
//关闭此StreamReader对象
sw.Close();
fs.Close();
}
private void button2_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream("C:\file.txt", FileMode.Open, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Flush();
// 使用StreamWriter来往文件中写入内容
sw.BaseStream.Seek(0, SeekOrigin.Begin);
// 把richTextBox1中的内容写入文件
sw.Write(content.Text);
//关闭此文件
sw.Flush();
sw.Close();
fs.Close();
} 展开
{
FileStream fs = new FileStream("C:\file.txt", FileMode.Open, FileAccess.Read);
StreamReader sw = new StreamReader(fs);
//使用StreamReader类来读取文件
sw.BaseStream.Seek(0, SeekOrigin.Begin);
// 从数据流中读取每一行,直到文件的最后一行,并在richTextBox1中显示出内容
this.content.Text = "";
string strLine = sw.ReadLine();
while (strLine != null)
{
this.content.Text += strLine + "\n";
strLine = sw.ReadLine();
}
//关闭此StreamReader对象
sw.Close();
fs.Close();
}
private void button2_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream("C:\file.txt", FileMode.Open, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Flush();
// 使用StreamWriter来往文件中写入内容
sw.BaseStream.Seek(0, SeekOrigin.Begin);
// 把richTextBox1中的内容写入文件
sw.Write(content.Text);
//关闭此文件
sw.Flush();
sw.Close();
fs.Close();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询