开发者

Saving an Int16 List to a binary file

I need to save data to a bi开发者_运维问答nary 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);
}


Have a look at BinaryFormatter: http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter%28v=vs.71%29.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜