I am trying to write a simple application that monitors the COM port and writes the incoming binary data to a file. So, I gathered a File class is provided, but looking at its methods list in the Help page, I see no method for writing individual bytes (and the Write methods seem to close the file after writing).
How can I write a byte array into a file, keep it open and repeat this as necessary?
(I am using Visual Studio 2005, if it’s relevant.)
Use a
FileStream:You use the
Writemethod to write a byte array (or part of it) to the stream:The
Writemethod doesn’t close the stream, you can write as many times you like.When you have written what you want, you use the
Closemethod to close the stream: