鴻蒙OS ObjectOutput

2022-10-17 12:00 更新

ObjectOutput

public interface ObjectOutput
extends DataOutput, AutoCloseable

ObjectOutput 擴(kuò)展了 DataOutput 接口以包括對(duì)象的寫(xiě)入。 DataOutput 包括用于輸出原始類(lèi)型的方法,ObjectOutput 擴(kuò)展了該接口以包括對(duì)象、數(shù)組和字符串。

Since:

JDK1.1

方法總結(jié)

修飾符和類(lèi)型 方法 描述
void close() 關(guān)閉流。
void flush() 沖洗流。
void write(byte[] b) 寫(xiě)入一個(gè)字節(jié)數(shù)組。
void write(byte[] b, int off, int len) 寫(xiě)入一個(gè)子字節(jié)數(shù)組。
void write(int b) 寫(xiě)入一個(gè)字節(jié)。
void writeObject(Object obj) 將對(duì)象寫(xiě)入底層存儲(chǔ)或流。
從接口 java.io.DataOutput 繼承的方法
writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF

方法詳情

writeObject

void writeObject(Object obj) throws IOException

將對(duì)象寫(xiě)入底層存儲(chǔ)或流。 實(shí)現(xiàn)此接口的類(lèi)定義了對(duì)象的編寫(xiě)方式。

參數(shù):

參數(shù)名稱(chēng) 參數(shù)描述
obj 要寫(xiě)入的對(duì)象

Throws:

Throw名稱(chēng) Throw描述
IOException 任何常見(jiàn)的輸入/輸出相關(guān)異常。

write

void write(int b) throws IOException

寫(xiě)入一個(gè)字節(jié)。 此方法將阻塞,直到實(shí)際寫(xiě)入字節(jié)。

指定者:

寫(xiě)入接口DataOutput

參數(shù):

參數(shù)名稱(chēng) 參數(shù)描述
b 字節(jié)

Throws:

Throw名稱(chēng) Throw描述
IOException 如果發(fā)生 I/O 錯(cuò)誤。

write

void write(byte[] b) throws IOException

寫(xiě)入一個(gè)字節(jié)數(shù)組。 此方法將阻塞,直到實(shí)際寫(xiě)入字節(jié)。

指定者:

寫(xiě)入接口DataOutput

參數(shù):

參數(shù)名稱(chēng) 參數(shù)描述
b 要寫(xiě)入的數(shù)據(jù)

Throws:

Throw名稱(chēng) Throw描述
IOException 如果發(fā)生 I/O 錯(cuò)誤。

write

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

寫(xiě)入一個(gè)子字節(jié)數(shù)組。

指定者:

寫(xiě)入接口DataOutput

參數(shù):

參數(shù)名稱(chēng) 參數(shù)描述
b 要寫(xiě)入的數(shù)據(jù)
off 數(shù)據(jù)中的起始偏移量
len 寫(xiě)入的字節(jié)數(shù)

Throws:

Throw名稱(chēng) Throw描述
IOException 如果發(fā)生 I/O 錯(cuò)誤。

flush

void flush() throws IOException

沖洗流。 這將寫(xiě)入任何緩沖的輸出字節(jié)。

Throws:

Throw名稱(chēng) Throw描述
IOException 如果發(fā)生 I/O 錯(cuò)誤。

close

void close() throws IOException

關(guān)閉流。 必須調(diào)用此方法來(lái)釋放與流關(guān)聯(lián)的任何資源。

指定者:

在接口 AutoCloseable 中關(guān)閉

Throws:

Throw名稱(chēng) Throw描述
IOException 如果發(fā)生 I/O 錯(cuò)誤。
以上內(nèi)容是否對(duì)您有幫助:
在線(xiàn)筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)