# FileSystemManager.write(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

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.
success function no Interface calls the successful callback function
fail function no Interface calls failed callback functions
complete function no Callback function at the end of an interface call (both successful and unsuccessful calls are executed)

object.encoding Legal value

value Introductions Minimum version
ucs2 Read in small endorder
ucs-2 Read in small endorder
Utf16le Read in small endorder
utf-16le Read in small endorder

# object.success callback

# parameter
# Object res
attribute type Introductions
bytesWritten number Number of bytes actually written to the file (note that the number of byte writes is not necessarily the same as the string characters written)

# object.fail callback

# parameter
# Object res
attribute type Introductions
errMsg string Error message

res.errMsg Legal value

value Introductions Minimum version
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()
// Open the file
  filePath: `${wx.env.USER_DATA_PATH}/hello.txt`, 
  flag: 'a+',
  success(res) {
    // Write file
      fd: res.fd,
      data: 'some text',
      success(res) {