「1234567」を含むファイル (test.txt) があります。ただし、FileStream.Read を使用して C# で読み込もうとすると、0 しか取得できません (この場合は 7 つのゼロ)。誰か教えてくれませんか?私はここで本当に迷っています。
編集:問題は解決しました。比較演算子が間違っています。ただし、現在は「49505152535455」が返されています
編集2:完了。記録のために、バイト変数を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();
}
}