一个Seek()方法不能被执行的问题
本人是新手,以下是本人写的一个简单的文本文件读写程序:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
char a;
FileStream fs1=new FileStream("D:\\file1.txt",FileMode.Open,FileAccess.ReadWrite);
FileStream fs2=new FileStream("D:\\file2.txt",FileMode.Open,FileAccess.ReadWrite);
StreamReader strmReader = new StreamReader(fs1);
StreamWriter strmWriter = new StreamWriter(fs2);
while (strmReader.Peek() != -1)
{
fs1.Seek(2, SeekOrigin.Current);
a = (char)strmReader.Read();
strmWriter.Write(a);
}
strmReader.Close();
strmWriter.Close();
}
}
}
执行后发现fs1.Seek(2, SeekOrigin.Current);这句没有起到作用,百思不得其解,感觉只要把fs1.Seek(2, SeekOrigin.Current)放在strmReader.Peek()后面就会被无视掉。
怎么办啊!望高手赐教!