读取文件内容
读取指定文件的二进制内容,返回 Buffer。可用于读取文本、图片或其他二进制文件。
接口说明
接口类型
readSandboxFile参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
deviceId | string | ✅ | 设备 ID |
file | string | ✅ | 文件绝对路径(filePath) |
返回值
返回 Buffer(二进制数据)。
基本使用
javascript
const _device = await apiInvoke('getDeviceInfo', {
deviceId: 'P72578581E07'
})
// 读取文件(返回 Buffer)
const _raw = await apiInvoke('readSandboxFile', {
deviceId: 'P72578581E07',
file: `${_device.info.sandboxPath}/result.txt`
})
const _buf = Buffer.from(_raw)
const _text = _buf.toString('utf-8')
console.log(_text)