私はウェブ上で次のコードを見つけました:
private byte [] StreamFile(string filename)
{
FileStream fs = new FileStream(filename, FileMode.Open,FileAccess.Read);
// Create a byte array of file stream length
byte[] ImageData = new byte[fs.Length];
//Read block of bytes from stream into the byte array
fs.Read(ImageData,0,System.Convert.ToInt32(fs.Length));
//Close the File Stream
fs.Close();
return ImageData; //return the byte data
}
ファイルをc#でbyte []に変換するために使用するのに十分な信頼性がありますか、それともこれを行うためのより良い方法がありますか?
fs.Close()ように、残りのコードを囲むtry-finallyステートメントのfinally-partを入力する必要がありますClose。