To stream a file to bytes in C#, you can use the FileStream
class to read the file and store the bytes in a byte array. Here's an example code snippet that shows how to accomplish this:
main.cs476 chars16 lines
In the example above, we first create a FileStream
object to read the file at the specified filePath
. We then create a buffer to hold the bytes, and read the bytes from the file into the buffer using the Read
method. Finally, we create a byte array to store the bytes that we've read from the file, and copy the bytes from the buffer to the byte array using the Array.Copy
method.
gistlibby LogSnag