鴻蒙OS Resource

2022-10-28 09:34 更新

Resource

java.lang.Object

|---java.io.InputStream

|---|---ohos.global.resource.Resource

public abstract class Resource
extends InputStream

描述可以從中讀取資源數(shù)據的輸入流。

資源實例只能使用 ResourceManager.getResource(int) 方法獲取。

Since:

1

構造函數(shù)摘要

構造函數(shù) 描述
Resource()

方法總結

修飾符和類型 方法 描述
abstract int available() 獲取可以從資源中讀取的總字節(jié)數(shù)。
abstract void close() 關閉此資源并釋放與流關聯(lián)的所有系統(tǒng)資源。
int read() 從資源中讀取下一個字節(jié)。
abstract int read(byte[] bytes, int off, int len) 從資源中讀取最多 len 個字節(jié)。
從類 java.io.InputStream 繼承的方法
mark, markSupported, read, reset, skip
從類 java.lang.Object 繼承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

構造函數(shù)詳細信息

Resource

public Resource()

方法詳情

available

public abstract int available() throws IOException

獲取可以從資源中讀取的總字節(jié)數(shù)。

覆蓋:

在類 InputStream 中可用

返回:

返回可以從資源中讀取的總字節(jié)數(shù)。

Throws:

Throw名稱 Throw描述
IOException 如果發(fā)生 I/O 錯誤,則引發(fā)此異常。

read

public abstract int read(byte[] bytes, int off, int len) throws IOException, IndexOutOfBoundsException, NullPointerException

從資源中讀取最多 len 個字節(jié)。

覆蓋:

讀入類 InputStream

參數(shù):

參數(shù)名稱 參數(shù)描述
bytes 指示讀取數(shù)據的緩沖區(qū)。
off 指示寫入數(shù)據的數(shù)組字節(jié)的起始偏移量。
len 指示要讀取的最大字節(jié)數(shù)。

返回:

返回讀入緩沖區(qū)的總字節(jié)數(shù); 如果由于到達流的末尾而沒有更多數(shù)據,則返回 -1。

Throws:

Throw名稱 Throw描述
IOException 如果發(fā)生 I/O 錯誤,則引發(fā)此異常。
NullPointerException 如果數(shù)組字節(jié)為空,則引發(fā)此異常。
IndexOutOfBoundsException 如果 off 為負數(shù)、len 為負數(shù)或 len 大于 bytes.length - off,則拋出此異常。

read

public int read() throws IOException

從資源中讀取下一個字節(jié)。

指定者:

讀入類 InputStream

返回:

返回下一個字節(jié)的數(shù)據; 如果已到達流的末尾,則返回 -1。

Throws:

Throw名稱 Throw描述
IOException 如果發(fā)生 I/O 錯誤,則引發(fā)此異常。

close

public abstract void close() throws IOException

關閉此資源并釋放與流關聯(lián)的所有系統(tǒng)資源。

指定者:

在接口 AutoCloseable 中關閉

指定者:

在接口Closeable中關閉

覆蓋:

在類 InputStream 中關閉

Throws:

Throw名稱 Throw描述
IOException 如果發(fā)生 I/O 錯誤,則引發(fā)此異常。
以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號