# FileSystemManager.writeFileSync(string filePath, string|ArrayBuffer data, string encoding)

with Promise style call: Not supported

Mini Program plugin: Support, need to Mini Program base library version no less than 2.19.2

FileSystemManager.writeFile The synchronous version of

# parameter

# string filePath

File path to write to (Local path)

# string|ArrayBuffer data

Text or binary data to write

# string encoding

Specifies the character encoding for writing to the file

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

# error

Error code Error message Introductions
fail No such file or directory, open ${filePath} Specified filePath Directory does not exist
fail permission denied, open ${dirPath} Specified filePath Path does not have write permissions
fail the maximum size of the file storage limit is exceeded Insufficient storage space
fail sdcard not mounted Android sdcard Mount failure

# sample code

const fs = wx.getFileSystemManager()
fs.writeFile({
  filePath: `${wx.env.USER_DATA_PATH}/hello.txt`, 
  data: 'some text  or  arrayBuffer',
  encoding: 'utf8',
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})

// Synchronous interface
try {
  const res = fs.writeFileSync(
    `${wx.env.USER_DATA_PATH}/hello.txt`, 
    'some text  or  arrayBuffer',
    'utf8'
  )
  console.log(res)
} catch(e) {
  console.error(e)
}