后浪云鸿蒙OS教程:鸿蒙OS ObjectInput

树叶云

ObjectInput

public interface ObjectInput
extends DataInput, AutoCloseable

ObjectInput 扩展了 DataInput 接口以包括对象的读取。 DataInput 包括用于输入原始类型的方法,ObjectInput 扩展了该接口以包括对象、数组和字符串。

Since:

JDK1.1

方法总结

修饰符和类型方法描述
intavailable()返回可以在不阻塞的情况下读取的字节数。
voidclose()关闭输入流。
intread()读取一个字节的数据。
intread(byte[] b)读入一个字节数组。
intread(byte[] b, int off, int len)读入一个字节数组。
ObjectreadObject()读取并返回一个对象。
longskip(long n)跳过 n 个字节的输入。
从接口 java.io.DataInput 继承的方法
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytes

方法详情

readObject

Object readObject() throws ClassNotFoundException, IOException

读取并返回一个对象。 实现此接口的类定义了从何处“读取”对象。

返回:

从流中读取的对象

Throws:

Throw名称Throw描述
ClassNotFoundException如果找不到序列化对象的类。
IOException如果发生任何常见的输入/输出相关异常。

read

int read() throws IOException

读取一个字节的数据。 如果没有可用的输入,此方法将阻塞。

返回:

读取的字节,如果到达流的末尾,则为 -1。

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误。

read

int read(byte[] b) throws IOException

读入一个字节数组。 此方法将阻塞,直到某些输入可用。

参数:

参数名称参数描述
b读取数据的缓冲区

返回:

实际读取的字节数,到达流末尾时返回-1。

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误。

read

int read(byte[] b, int off, int len) throws IOException

读入一个字节数组。 此方法将阻塞,直到某些输入可用。

参数:

参数名称参数描述
b读取数据的缓冲区
off数据的起始偏移量
len读取的最大字节数

返回:

实际读取的字节数,到达流末尾时返回-1。

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误。

skip

long skip(long n) throws IOException

跳过 n 个字节的输入。

参数:

参数名称参数描述
n要跳过的字节数

返回:

跳过的实际字节数。

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误。

available

int available() throws IOException

返回可以在不阻塞的情况下读取的字节数。

返回:

可用字节数。

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误。

close

void close() throws IOException

关闭输入流。 必须调用以释放与流关联的任何资源。

指定者:

在接口 AutoCloseable 中关闭

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误。

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/178491.html<

(0)
运维的头像运维
上一篇2025-03-26 03:08
下一篇 2025-03-26 03:09

相关推荐

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注