Base Library 2.1.0 or later is required. For earlier versions, see compatibility handling.
Called in Promise style: Not supported
Mini Program plugin: Supported, requires Mini Program base library version no lower than 2.19.2
WeChat for Harmony OS: Supported
Related documents: File System
Feature Description
The synchronous version of FileSystemManager.appendFile
Parameters
string filePath
The local file path to which content should be appended
string|ArrayBuffer data
The text or binary data to be appended
string encoding
Specifies the character encoding for writing the file.
Valid values for encoding
| Value | Description | Minimum Version |
|---|---|---|
| ascii | ||
| base64 | ||
| binary | ||
| hex | ||
| ucs2 | Read using little-endian byte order | |
| ucs-2 | Read using little-endian byte order | |
| utf16le | Read using little-endian byte order | |
| utf-16le | Read using little-endian byte order | |
| utf-8 | ||
| utf8 | ||
| latin1 |
Errors
| Error Code | Error Message | Description |
|---|---|---|
| 1300001 | operation not permitted | The operation is not permitted (for example, filePath expects a file but a directory was provided) |
| 1300002 | no such file or directory ${path} | The file/directory does not exist, or the parent directory of the target file path does not exist |
| 1300005 | Input/output error | Input/output stream is unavailable |
| 1300009 | bad file descriptor | Invalid file descriptor |
| 1300013 | permission denied | Permission error; the file is read-only or write-only |
| 1300014 | Path permission denied | No permission for the provided path |
| 1300020 | not a directory | The path specified by dirPath is not a directory; this commonly occurs when the parent path of the specified write path is a file |
| 1300021 | Is a directory | The specified path is a directory |
| 1300022 | Invalid argument | Invalid argument; check whether length or offset is out of bounds |
| 1300036 | File name too long | File name is too long |
| 1300066 | directory not empty | The directory is not empty |
| 1300201 | system error | System interface call failed |
| 1300202 | the maximum size of the file storage limit is exceeded | Insufficient storage space, or file size exceeds the limit (limit is 100M) |
| 1300203 | base64 encode error | Character encoding conversion failed (e.g., incorrect base64 format) |
| 1300300 | sdcard not mounted | Failed to mount Android SD card |
| 1300301 | unable to open as fileType | Unable to open the file as fileType |
| 1301000 | permission denied, cannot access file path | No access permission for the target path (user directory) |
| 1301002 | data to write is empty | The data to be written is empty |
| 1301003 | illegal operation on a directory | This operation is not allowed on a directory (e.g., the specified filePath is an existing directory) |
| 1301004 | illegal operation on a package directory | This operation is not allowed on the code package directory |
| 1301005 | file already exists ${dirPath} | A file or directory with the same name already exists |
| 1301006 | value of length is out of range | The provided length is invalid |
| 1301007 | value of offset is out of range | The provided offset is invalid |
| 1301009 | value of position is out of range | position value is out of range |
| 1301100 | store directory is empty | The store directory is empty |
| 1301102 | unzip open file fail | Failed to open the compressed file |
| 1301103 | unzip entry fail | Failed to extract a single file |
| 1301104 | unzip fail | Extraction failed |
| 1301111 | brotli decompress fail | Brotli decompression failed (e.g., the specified compressionAlgorithm does not match the actual compression format of the file) |
| 1301112 | tempFilePath file not exist | The file specified by tempFilePath cannot be found |
| 1302001 | fail permission denied | The specified fd path lacks read/write permission |
| 1302002 | excced max concurrent fd limit | The number of fds has reached the limit |
| 1302003 | invalid flag | Invalid flag |
| 1302004 | permission denied when open using flag | Unable to open the file using the specified flag |
| 1302005 | array buffer does not exist | arrayBuffer was not provided |
| 1302100 | array buffer is readonly | arrayBuffer is read-only |
Sample Code
const fs = wx.getFileSystemManager()
fs.appendFile({
filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,
data: 'some text',
encoding: 'utf8',
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})
// 同步接口
try {
fs.appendFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`, 'some text', 'utf8')
} catch(e) {
console.error(e)
}