📌 从基础库 3.125.4 版本开始支持
参数 | 类型 | 说明 |
---|---|---|
filePath | string | 要追加内容的文件路径 (本地路径) |
data | string | ArrayBuffer | 要追加的文本或二进制数据 |
encoding | string | 指定写入文件的字符编码 |
值 | 说明 |
---|---|
utf-8 | UTF-8 编码 |
utf8 | UTF-8 编码(别名) |
binary | 二进制格式 |
const fs = xhs.getFileSystemManager() // 异步调用 fs.appendFile({ filePath: `${xhs.env.USER_DATA_PATH}/hello.txt`, data: 'some text', encoding: 'utf8', success(res) { console.log(res) }, fail(res) { console.error(res) } }) // 同步接口 try { fs.appendFileSync(`${xhs.env.USER_DATA_PATH}/hello.txt`, 'some text', 'utf8') } catch(e) { console.error(e) }