# FileSystemManager.open(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 the file and return the 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' |
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.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 | |
初始值 | 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 |
# object.success callback
# parameter
# Object res
attribute | type | Introductions |
---|---|---|
fd | string | File descriptor |
# object.fail callback
# parameter
# Object res
attribute | type | Introductions |
---|---|---|
errMsg | string | Error message |
res.errMsg Legal value
value | Introductions | Minimum version |
---|---|---|
fail No such file or directory "${filePath}" | There is no parent directory |
# sample code
const fs = wx.getFileSystemManager()
fs.open({
filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+',
success(res) {
console.log(res.fd)
}
})