# WriteResult FileSystemManager.writeSync(Object object)
Start from base library version 2.16.1. Please remaining backward compatible.
with Promise style call: Not supported
Mini Program plugin: Support, need to Mini Program base library version no less than 2.19.2
Synchronous write file
# parameter
# Object object
attribute | type | Default values | Required | Introductions |
---|---|---|---|---|
fd | string | yes | File descriptor. fd adopt FileSystemManager.open or FileSystemManager.openSync Interface acquisition | |
data | string/ArrayBuffer | yes | Write content of type String or ArrayBuffer | |
offset | number | 0 | no | Only in data Type is ArrayBuffer When valid, decided arrayBuffe To be written to in the arrayBuffer Index in, default 0 |
length | number | no | Only in data Type is ArrayBuffer Specifies the number of bytes to write, and defaults to arrayBuffer Offset from 0 offset Number of bytes remaining after 1 byte | |
encoding | string | utf8 | no | Only in data Type is String Specifies the character encoding to write to the file, and defaults to utf8 |
position | number | no | Specifies the offset at the beginning of the file, where the data will be written. when position Not passed or passed in Number Type, the data is written to the current pointer location. |
object.encoding Legal value
value | Introductions | Minimum version |
---|---|---|
ascii | ||
base64 | ||
binary | ||
hex | ||
ucs2 | Read in small endorder | |
ucs-2 | Read in small endorder | |
Utf16le | Read in small endorder | |
utf-16le | Read in small endorder | |
utf-8 | ||
utf8 | ||
latin1 |
# Return value
# WriteResult
File write result
# error
Error code | Error message | Introductions |
---|---|---|
bad file descriptor | Invalid file descriptor | |
fail permission denied | Specified fd Path does not have write permissions | |
fail sdcard not mounted | android sdcard Mount failure |
# sample code
const fs = wx.getFileSystemManager()
const fd = fs.openSync({
filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+'
})
const res = fs.writeSync({
fd: fd,
data: 'some text'
})
console.log(res.bytesWritten)