我有一个StreamReader,它会不时地检查一个简单的文本文件是否还有更多内容需要读取。它使用peek属性。问题是,在我使用peek时,位置会发生改变,尽管不应该发生这种情况。
FileStream m_fsReader = new FileStream(
m_strDataFileName,
FileMode.OpenOrCreate,
FileAccess.Read,
FileShare.ReadWrite );
StreamReader m_SR = new StreamReader(m_fsReader);
Console.WriteLine("IfCanRead SR Position " + m_fsReader.Position +
" and Length " + m_fsReader.Length);
if (m_SR.Peek() == -1) {
Console.WriteLine("IfCanRead false 2 SR Position " +
m_fsReader.Position + " and Length " + m_fsReader.Length);
return false;
}
else {
Console.WriteLine("IfCanRead true 2 SR Position " +
m_fsReader.Position + " and Length " + m_fsReader.Length);
return true;
}