我有一段時間檢查是否有更多的簡單文本文件讀取的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