मुझे वेब पर निम्न कोड मिला:
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 # में, या ऐसा करने का एक बेहतर तरीका है?
fs.Close()कोशिश-अंत में दिए गए बयान के अंत में भाग देना चाहिए जो बाकी कोड को जोड़ताCloseहै , यह सुनिश्चित करने के लिए कि वास्तव में कहा जाता है।