开发 API 文件 FileSystemManager FileSystemManager.readFile
# FileSystemManager.readFile
更新时间:2024-09-18 14:46:38
这是一个实验性功能
读取文件数据。
# readFile(options: ReadFileOptions): Promise<ReadFileResult>
# 参数
| 参数 | 类型 | 必填 |
|---|---|---|
| options | ReadFileOptions | 是 |
# ReadFileOptions
属性
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| filePath | string | 是 | 要读取数据的文件本地路径 | |
| encoding | 'ascii' | 'base64' | 'binary' | 'hex' | 'ucs2' | 'ucs-2' | 'utf16le' | 'utf-8' | 'utf8' | 'latin1' | 否 | 读取数据的字符编码,不传入则使用 ArrayBuffer | |
| position | number | 0 | 否 | 文件中读取数据的起始位置 (Byte) |
| length | number | 否 | 文件中读取数据的长度 (Byte),不传入则读取到文件末尾 | |
| success | (result: T) => void | 否 | 接口调用成功的回调函数 | |
| fail | (error: U) => void | 否 | 接口调用失败的回调函数 | |
| complete | (resultOrError: T | U) => void | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
# 返回值
# Promise<ReadFileResult>
ReadFileResult
属性
| 属性 | 类型 | 说明 |
|---|---|---|
| errMsg | string | |
| errCode | number | |
| errno | number | |
| data | string | ArrayBuffer | 读取的文件数据 |
# 示例代码
上一篇:《FileSystemManager.readdirSync》
下一篇:《FileSystemManager.writeFile》
仍有疑问? 前往社区提问