我有一段时间检查是否有更多的简单文本文件读取的StreamReader。它使用peek属性。问题是,当我使用偷看时,位置发生了变化,所以不要假设。StreamReader,C#,偷看
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;
}
发布您的相关代码,因为Peek不*消耗任何字节。这就是Peek的观点。 – 2009-11-15 14:06:29
添加相关数据 – 2009-11-15 14:13:46
我假设你知道File.ReadAllBytes和其他类似的方法,但它们不能用于你的特定程序... – Will 2009-11-15 14:41:59