没有,干吗要用byte作数字型的表示呢,
这年头不会为了节约几个字节用byte吧

解决方案 »

  1.   

    那怎么办,0-256的数字不能定义为byte吗,非要定义成short的?
      

  2.   

    不是节约,是有这个需要,通讯协议是这样规定的,一个字节可能传递的值就是大于127的,所以byte类型做不到.定义成short的就与通讯协议不一致了.
      

  3.   

    InputStream:
    public abstract int read()throws IOException
        Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown. 
    A subclass must provide an implementation of this method.OutputStream:
    public abstract void write(int b) throws IOException
        Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.