I need to save data to a binary file. It is of type List<Int16>
. How can I write this data to the file?
using(var file = File.Create("out.bin"))
using (var writer = new BinaryWriter(file))
{
foreach (short value in list)
{
writer.Write(value);
}
}
note this assumes you want to use your CPUs endianness.
Try to use
using(BinaryWriter binWriter = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
binWriter.Write(what_you_want);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.