How can I read a file as unsigned bytes in Java?

前端 未结 5 1246
名媛妹妹
名媛妹妹 2021-01-12 14:39

How can I read a file to bytes in Java?

It is important to note that all the bytes need to be positive, i.e. the negative range cannot be used.

Can this be d

5条回答
  •  感情败类
    2021-01-12 15:09

    With the unsigned API in Java 8 you have Byte.toUnsignedInt. That'll be a lot cleaner than manually casting and masking out.

    To convert the int back to byte after messing with it of course you just need a cast (byte)value

提交回复
热议问题