简体   繁体   中英

Java I/O method types

Quick theoretical question:

Why are java Input/Output methods of Integer type?

For example:

InputStream
int read()
int read(byte cbuf[])
int read(byte cbuf[], int offset, int length)

第一个以int形式读取无符号字节(由于Java的字节是有符号的,因此您需要更大的数据类型来保存0-255之间的值),后两个方法返回读取的字节数。

Why are java Input/Output methods of Integer type?

They aren't. They are of int type.

The reason read() returns an int is so that it can return the out-of-band value -1, meaning end of stream.

The reason the other read() methods return int is to indicate the number of bytes received, or -1 indicating end of stream.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM