简体   繁体   中英

Saving an Int16 List to a binary file

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM