java - JAVA中的流结束

标签 java io inputstream

我对出现的以下语句感到困惑here

The basic read() method of the InputStream class reads a single unsigned byte of data and returns the int value of the unsigned byte. This is a number between 0 and 255. If the end of stream is encountered, it returns -1 instead; and you can use this as a flag to watch for the end of stream.

由于一个字节最多可以表示 256 个整数,我看不出它如何表示 0 到 256 和 -1。有人可以评论我在这里缺少的东西吗?

最佳答案

InputStream#read() 的返回类型是一个 int,如果值在 0-255 范围内,则可以将其读取为 byte

关于java - JAVA中的流结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14449473/

相关文章:

java - Spring @Order 注释未按正确顺序加载

java - 在 Gradle 项目 IntelliJ 中激活断言

Java:向文件写入/读取字符会产生不同的结果

postgresql - 如何找到消耗最多 I/O 的 postgresql 查询

java - Java Inputstream,NoFly服务器

java - HttpURLConnection返回的InputStream中的数据在读取之前存储在哪里?

java - 来自相对路径的 InputStream

java - Stream 从一个对象创建两个对象并进一步处理

java - 结构化数据文件读取器类

java - 使用 simple-odf 优化 ods 文件的写入