# string FileSystemManager.openSync(Object object)
基础库 2.16.1 开始支持,低版本需做兼容处理。
小程序插件:支持,需要小程序基础库版本不低于 2.19.2
# 功能描述
同步打开文件,返回文件描述符
# 参数
# Object object
属性 | 类型 | 默认值 | 必填 | 说明 | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
filePath | string | 是 | 文件路径 (本地路径) | ||||||||||||||||||||||||||||
flag | string | r | 否 | 文件系统标志,默认值: 'r' | |||||||||||||||||||||||||||
|
# 返回值
# string
文件描述符
# 错误
错误码 | 错误信息 | 说明 |
---|---|---|
fail no such file or directory "${filePath}" | 上级目录不存在 |
# 示例代码
const fs = wx.getFileSystemManager()
const fd = fs.openSync({
filePath: <code>${wx.env.USER_DATA_PATH}/hello.txt</code>,
flag: 'a+'
})
console.log(fd)