I've got a file (test.txt) which contains "1234567". However when I try to read it on C# using FileStream.Read, I get only 0s (seven zeroes in this case). Could anyone tell me why? I'm really lost here.
Edit: Problem solved, wrong comparision operator. However now it's returning "49505152535455"
Edit 2: Done. For the record, I had to output the byte variable as a char.
using System;
using System.IO;
class Program
{
static void Main()
{
FileStream fil = null;
try
{
fil = new FileStream("test.txt", FileMode.Open,FileAccess.Read);
byte[] bytes = new byte[fil.Length];
int toRead = (int)fil.Length;
int Read = 0;
while (toRead < 0)
{
int n = fil.Read(bytes, Read, toRead);
Read += n;
toRead -= n;
}
//Tried this, will only return 0000000
foreach (byte b in bytes)
{
Console.Write(b.ToString());
}
}
catch (Exception exc)
{
Console.WriteLine("Oops! {0}", exc.Message);
}
finally
{
fil.Close();
}
Console.ReadLine();
}
}