string getText = "";
FileStream fs = new FileStream("E:\\madh.txt", FileMode.Open, FileAccess.Read);
StreamReader m_streamReader = new StreamReader(fs);
//使用StreamReader类来读取文件
m_streamReader.BaseStream.Seek(0,SeekOrigin.Begin);
//从数据流中读取每一行,直到文件的最后一行,并在richTextBox1中显示出内容
//this.richTextBox1.Text = "";
string strLine = m_streamReader.ReadLine();
while(strLine!=null)
{
if(strLine.Length >= 6)
strLine = strLine.Substring(6);
//this.richTextBox1.Text += strLine + "\n";
getText += strLine + "\r\n";
Console.WriteLine(strLine);
strLine = m_streamReader.ReadLine();
}
//关闭此StreamReader对象
m_streamReader.Close();
//Console.ReadLine();
//创建一个文件流,用以写入或者创建一个StreamWriter
FileStream fs1 = new FileStream("E:\\file.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs1);
m_streamWriter.Flush();
//使用StreamWriter来往文件中写入内容
m_streamWriter.BaseStream.Seek(0, SeekOrigin.Begin);
//把getText中的内容写入文件
m_streamWriter.Write(getText);
//关闭此文件
m_streamWriter.Flush();
m_streamWriter.Close();
[此贴子已经被作者于2006-8-25 9:16:03编辑过]