unless you are looking for a specific value using Peek()
why not use .Read()
for example
string line;
System.IO.StreamReader file = new System.IO.StreamReader(strfn);
while((line = file.ReadLine()) != null)
{
this.richTextBox1.AppendText(line+"\n");//you can replace this line to fit your UseCase
}
If you want a Cleaner example of how this could be done you could do something like what I have posted below it readable and you can plug in your own text file values and Debug this to see that it will work. Reading and Writing
string tempFile = Path.GetTempFileName();
using(var sr = new StreamReader("file.txt"))
{
using(var sw = new StreamWriter(tempFile))
{
string line;
while((line = sr.ReadLine()) != null)
{
if(line != "BlaBlaBla")
sw.WriteLine(line);
}
}
}
Here is another option you could try
From a Stream
, if you Read(buffer, offset, count)
you'll get a non-positive result, and if you Peek()
you'll get a negative result.
With a BinaryReader
, the documentation suggests that PeekChar()
should return negative:
Return Value
Type: System.Int32
The next available character, or -1 if no more characters are available or the stream does not support seeking.
are you sure this isn't a corrupt stream? i.e. the remaining data cannot form a complete char
from the given encoding?