Is it possible to read/write bits from a file using JAVA?

后端 未结 9 942
一生所求
一生所求 2020-12-09 21:34

To read/write binary files, I am using DataInputStream/DataOutputStream, they have this method writeByte()/readByte(), but what I want to do is read/write bits? Is it possib

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 22:25

    Bits are packaged in bytes and apart from VHDL/Verilog I have seen no language that allows you to append individual bits to a stream. Cache up your bits and pack them into a byte for a write using a buffer and bitmasking. Do the reverse for read, i.e. keep a pointer in your buffer and increment it as you return individually masked bits.

提交回复
热议问题