Why Java OutputStream.write() Takes Integer but Writes Bytes

后端 未结 5 706
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 07:01

I am writing an OutputStream, just noticed this in the OutputStream interface,

   public abstract void write(int b) throws IOException;

Thi

5条回答
  •  星月不相逢
    2020-12-05 07:24

    according to javadoc for OutputStream, the 24 high-order bits are ignored by this function. i think the method exists for compatibility reasons: therefore you don't need to convert to byte first and you can simply pass an integer.

    regards

提交回复
热议问题