My problem is fairly simple for those used to CLI programming!
I basically have an "unsigned char" type array that I need to dump to a file and later be able to read it back, like an EEPROM memory. It's quite simple, but I am having difficulty to find the information on how that could be accomplished. I tried to use StreamWriter but I did not succeed. The code bellow compiles, but all I get is the "System.Byte[]" message on the created file...
Already the first line of the MSDN StreamWriter doc page could have been a useful indicator that this isn't what you actually want, BTW:
Originally Posted by MSDN
Implements a TextWriter for writing characters to a stream in a particular encoding.
[...] And ah! After I succeed writing it, how to read it back??
Reading it back is much like writing it; you'd even use the same framework class. Just study the MSDN docs.
However, if what you actually want is text file handling, a StreamWritermay very well be what you're looking for. It just doesn't have a Write(array<unsigned char> ^) overload (the C++ unsigned char is equivalent to the .NET System::Byte). Appropriate objects to pass to TextWriter::Write() are, among others, array<System::Char> ^ (note the capital C, where the equivalent native item type is wchar_t rather than unsigned char) or simply System::String ^.
Re: Trying to dump an "unsigned char" array to file!
Hi Eri523! Thank you so much for your help. I'll definitively study the FileStream class and implement it. No, I'm not handling text files, so you surely saved me from a lot of headaches
Re: Trying to dump an "unsigned char" array to file!
Hey Eri523!
I used FileStream and it worked 100% fine. I also used OpenFileDialog and SaveFileDialog to browse directories and provide the file path. It was a piece of cake!
Bookmarks