テキストファイルを読み取り、次のように出力するc#コードがあります。
StreamReader sr = new StreamReader(File.OpenRead(ofd.FileName));
byte[] buffer = new byte[100]; //is there a way to simply specify the length of this to be the number of bytes in the file?
sr.BaseStream.Read(buffer, 0, buffer.Length);
foreach (byte b in buffer)
{
label1.Text += b.ToString("x") + " ";
}
とにかく、ファイルのバイト数を知ることができますか?
の長さを事前に知りたいbyte[] buffer
ので、Read 関数でbuffer.length
3 番目の引数として単純に渡すことができます。