0

テキストファイルを読み取り、次のように出力する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.length3 番目の引数として単純に渡すことができます。

4

4 に答える 4