Reputation: 51
I need to save data to a binary file. It is of type List<Int16>
. How can I write this data to the file?
Upvotes: 0
Views: 303
Reputation: 1064184
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.
Upvotes: 3
Reputation: 33272
Have a look at BinaryFormatter: http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter%28v=vs.71%29.aspx
Upvotes: 0
Reputation: 23276
Try to use
using(BinaryWriter binWriter = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
binWriter.Write(what_you_want);
}
Upvotes: 2