How to read file binary in C#?

后端 未结 6 1321
醉酒成梦
醉酒成梦 2020-11-28 07:50

I want to make a method that takes any file and reads it as an array of 0s and 1s, i.e. its binary code. I want to save that binary code as a text file. Can you help me? Tha

6条回答
  •  执笔经年
    2020-11-28 08:33

    using (FileStream fs = File.OpenRead(binarySourceFile.Path))
        using (BinaryReader reader = new BinaryReader(fs))
        {              
            // Read in all pairs.
            while (reader.BaseStream.Position != reader.BaseStream.Length)
            {
                Item item = new Item();
                item.UniqueId = reader.ReadString();
                item.StringUnique = reader.ReadString();
                result.Add(item);
            }
        }
        return result;  
    

提交回复
热议问题