웹에서 다음 코드를 찾았습니다.
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.