简体   繁体   English

Java I / O方法类型

[英]Java I/O method types

Quick theoretical question: 快速理论问题:

Why are java Input/Output methods of Integer type? 为什么Java输入/输出方法为Integer类型?

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? 为什么Java输入/输出方法为Integer类型?

They aren't. 他们不是。 They are of int type. 它们是int类型的。

The reason read() returns an int is so that it can return the out-of-band value -1, meaning end of stream. read()返回int的原因是,它可以返回带外值-1,这意味着流的结尾。

The reason the other read() methods return int is to indicate the number of bytes received, or -1 indicating end of stream. 其他read()方法返回int是指示接收到的字节数,或者-1指示流的结束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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