FileSystemManager.appendFileSync
收藏我的收藏
基础库 2.60.0 开始支持本方法,低版本需做兼容处理,这是一个同步方法。
在文件结尾追加内容,只有用户目录(ttfile://user)下的文件可以追加,文件不存在时会新建。
| 前提条件 | 无 |
| 业务背景 | 无 |
| 使用限制 | 无 |
| 注意事项 | 无 |
| 支持沙盒 | 否 |
| 相关教程 | 无 |
语法
FileSystemManager.appendFileSync(filePath, data, encoding)
参数说明
filePath
| 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
|---|---|---|---|---|
| string | 是 | 要追加内容的文件的路径,必须以 ttfile://user 开头 | 2.60.0 |
data
| 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
|---|---|---|---|---|
| string | arraybuffer | 是 | 要写入的文本或二进制数据 | 2.60.0 |
encoding
| 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
|---|---|---|---|---|
| enum | 否 | 指定写入文件的字符编码 | 2.60.0 |
encoding 的合法值
| 值 | 说明 | 最低支持版本 |
|---|---|---|
| utf-8 | 2.60.0 | |
| ascii | 2.60.0 | |
| base64 | 2.60.0 | |
| binary | ISO-8859-1 | 2.60.0 |
| hex | 十六进制 | 2.60.0 |
| ucs2 | 以小端序读取 | 2.60.0 |
| ucs-2 | 以小端序读取 | 2.60.0 |
| utf16le | 以小端序读取 | 2.60.0 |
| utf-16le | 以小端序读取 | 2.60.0 |
| utf8 | 2.60.0 | |
| latin1 | ISO-8859-1 | 2.60.0 |
返回值
无
错误码
| errorCode | errMsg | errorType | 说明 | 最低支持版本 |
|---|---|---|---|---|
| 109301 | permission denied, %s %s | D | 路径没有权限 请查看filePath参数是否正确 | 2.60.0 |
| 109302 | no such file or directory, %s %s | D | 文件不存在 请查看filePath参数是否正确 | 2.60.0 |
| 161799 | params filePath is required | D | 参数filePath为空 请查看filePath参数是否正确 | 2.60.0 |
扫码体验
请使用字节宿主APP扫码
代码示例
const fs = tt.getFileSystemManager() fs.appendFile({ filePath: `ttfile://user/example.txt`, data: "Hello World", encoding: "utf8", success(res) { console.log(res) }, fail(res) { console.error(res) }, }) // 同步接口 try { fs.appendFileSync(`ttfile://user/example.txt`, "Hello World", "utf8") } catch (e) { console.error(e) }
