Questions about inputStream.read () return value

A. Why intputStream.read () returns an int

  InputStream.read () returns a value of int, but each time it reads a byte, the reason is because C ++ signed or unsigned byte, it is the range [0-255], but not unsigned byte java

  So is Java's byte [] -128-127, if it is to receive a byte there will be some number will be represented as a negative number, so I used to receive int.

 

II. Why intputStream.read (byte []) but can be used byte

  In fact, because of the nature of byte or byte code, save the original binary data, but is printed out after calling the toString () method so became a decimal number, here is toString () method

  Professional interpretation. As long as no print byte is no problem, so you can use a byte array to receive

java.lang.Byte.toString () Returns a String object of this byte value representative. This value is converted to signed decimal notation, and returned as a string, exactly as if the byte value is given as an argument to the toString ( byte ) method. From the original tutorial] [EBEY, commercial reprint please contact the author authorized, non-commercial please retain the original link: HTTPS: // www.yiibai.com/java/lang/byte_tostring.html

 

Guess you like

Origin www.cnblogs.com/lollong/p/11443092.html