FileSystemManager.appendFileSync
基础库 3.1.0 开始支持本方法,这是一个同步方法。
在文件结尾追加内容,文件不存在时会新建。只有用户目录ttfile://user下的文件可以追加。
| 前提条件 | 无 | 
| 业务背景 | 无 | 
| 使用限制 | 无 | 
| 注意事项 | 无 | 
| 相关教程 | 无 | 
语法
FileSystemManager.appendFileSync(filePath, data, encoding)
参数说明
filePath
| 类型 | 默认值 | 必填 | 说明 | 最低支持版本 | 
|---|---|---|---|---|
| string | 是 | 要追加内容的文件路径,必须是用户目录,以 ttfile://user 开头 | 3.1.0 | 
data
| 类型 | 默认值 | 必填 | 说明 | 最低支持版本 | 
|---|---|---|---|---|
| string | 是 | 要写入的文本或二进制数据。支持 string 和 arraybuffer 类型 | 3.1.0 | 
encoding
| 类型 | 默认值 | 必填 | 说明 | 最低支持版本 | 
|---|---|---|---|---|
| enum | utf-8 | 是 | 指定写入文件的字符编码 | 3.1.0 | 
encoding 的合法值
| 值 | 说明 | 最低支持版本 | 
|---|---|---|
| utf-8 | 3.1.0 | |
| ascii | 3.1.0 | |
| base64 | 3.1.0 | |
| binary | ISO-8859-1 | 3.1.0 | 
| hex | 十六进制 | 3.1.0 | 
| ucs2 | 以小端序读取 | 3.1.0 | 
| ucs-2 | 以小端序读取 | 3.1.0 | 
| utf16le | 以小端序读取 | 3.1.0 | 
| utf-16le | 以小端序读取 | 3.1.0 | 
| utf8 | 3.1.0 | |
| latin1 | ISO-8859-1 | 3.1.0 | 
返回值
无
错误码
| errNo | errMsg | 说明 | 最低支持版本 | 
|---|---|---|---|
| 20000 | appendFile:fail filePath is invalid | filePath 参数错误 | 3.1.0 | 
| 21101 | appendFile:fail permission denied, appendFile %s | 文件路径不可写 | 3.1.0 | 
| 21102 | appendFile:fail no such file or directory, appendFile %s | filePath 文件不存在 | 3.1.0 | 
| 21103 | appendFile:fail user dir saved file size limit exceeded | 超出目录大小限制 | 3.1.0 | 
| 21104 | appendFile:fail operation not permitted, appendFile %s | filePath 类型不是文件 | 3.1.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) }
