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

Open file synchronously, return file descriptor

# parameter

# Object object

attribute type Default values Required Introductions
filePath string yes File path (Local path)
flag string r no File system flag, default: 'r'

object.flag Legal value

value Introductions Minimum version
a Open the file for appending. If the file does not exist, create the file
ax Similar to 'a ', but fails if path exists
a+ Open the file for reading and appending. If the file does not exist, create the file
ax+ Similar to 'a + ', but fails if path exists
as Open the file for appending (in sync mode). If the file does not exist, create the file
as+ Open files for reading and appending (in synchronous mode). If the file does not exist, create the file
r Open the file for reading. If the file does not exist, an exception occurs
r+ Open files for reading and writing. If the file does not exist, an exception occurs
in Open the file for writing. Create a file if it does not exist, and truncate it if it exists
wx Similar to 'w ', but fails if path exists
w+ Open files for reading and writing. Create a file if it does not exist, and truncate it if it exists
wx+ Similar to 'w + ', but fails if path exists

# Return value

# string

File descriptor

# error

Error code Error message Introductions
fail No such file or directory "${filePath}" There is no parent directory

# sample code

const fs = wx.getFileSystemManager()
const fd = fs.openSync({
  filePath: `${wx.env.USER_DATA_PATH}/hello.txt`, 
  flag: 'a+'
})
console.log(fd)