指南 接口 其他

FileSystemManager qg.getFileSystemManager()

获取全局唯一的文件管理器

返回值

FileSystemManager 文件管理器对象

FileSystemManager.access(Object object)

判断文件/目录是否存在

参数 Object object

属性键值类型是否必填说明
pathString要判断是否存在的文件/目录路径
successFunction接口调用成功的回调函
failFunction(Object res)接口调用失败的回调函数
completeFunction接口调用结束的回调函数
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
no such file or directory文件/目录不存在

FileSystemManager.accessSync(path)

FileSystemManager.access 的同步版本,判断文件/目录是否存在

参数列表

参数键值类型是否必填说明
pathString要判断是否存在的文件/目录路径

FileSystemManager.appendFile(Object object)

在文件结尾追加内容

参数 Object object

属性键值类型是否必填说明
filePathString要追加内容的文件路径
dataString/ArrayBuffer要追加的文本或二进制数据
encodingString指定写入文件的字符编码,当前支持:utf8、binary
successFunction接口调用成功的回调函数
failFunction(Object res)接口调用失败的回调函数
completeFunction接口调用结束的回调函数
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
no such file or directory指定的 filePath 文件不存在, 或是一个目录
permission denied指定目标文件路径没有写权限

FileSystemManager.appendFileSync(filePath, data, encoding)

FileSystemManager.appendFile 的同步版本,在文件结尾追加内容

参数列表

参数参数类型是否必填说明
filePathString要追加内容的文件路径
dataString/ArrayBuffer要追加的文本或二进制数据
encodingString指定写入文件的字符编码,当前支持:utf8、binary

FileSystemManager.copyFile(Object object)

复制文件异步方式

参数 Object object

属性键值类型是否必填说明
srcPathString源文件路径,只可以是普通文件
destPathString目标文件路径
successFunction接口调用成功的回调函
failFunction(Object res)接口调用失败的回调函数
completeFunction接口调用结束的回调函数
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
no such file or directory源文件不存在,或目标文件路径的上层目录不存在
permission denied指定目标文件路径没有写权限

FileSystemManager.copyFileSync(srcPath, destPath)

FileSystemManager.copyFile 的同步版本,拷贝文件

参数列表

参数参数类型是否必填说明
srcPathString源文件路径,只可以是普通文件
destPathString目标文件路径

返回值

boolean值,文件复制成功与否,true代表成功,false代表失败

FileSystemManager.getFileInfo(Object object)

获取本地临时文件或本地用户文件的文件信息

参数 Object object

属性键值类型是否必填说明
filePathString要读取的文件路径
successFunction接口调用成功的回调函
failFunction(Object res)接口调用失败的回调函数
completeFunction接口调用结束的回调函数

success回调函数的参数 Object res

属性键值类型说明
sizeNumber文件大小,以字节为单位
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
file not exist指定的路径找不到文件

FileSystemManager.mkdir(Object object)

创建目录

参数 Object object

属性键值类型是否必填说明
dirPathString创建的目录路径
successFunction接口调用成功的回调函
failFunction(Object res)接口调用失败的回调函数
completeFunction接口调用结束的回调函数
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
no such file or directory上级目录不存在
permission denied指定目标文件路径没有写权限
file already exists有同名文件或目录

FileSystemManager.mkdirSync(dirPath, recursive)

FileSystemManager.mkdir 的同步版本,创建目录

参数列表

参数参数类型是否必填说明
dirPathString创建的目录路径
recursiveString是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。

FileSystemManager.readFile(Object object)

读取本地文件内容异步方式

参数 Object object

属性键值类型是否必填说明
filePathString要读取的文件的路径
encodingString指定读取文件的字符编码,默认为 binary
successFunction接口调用成功的回调函
failFunction(Object res)接口调用失败的回调函数
completeFunction接口调用结束的回调函数

success回调函数的参数 Object res

属性键值类型说明
dataString/ArrayBuffer读取到的文本或二进制数据
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
no such file or directory上级目录不存在
permission denied指定目标文件路径没有写权限

FileSystemManager.readFileSync(filePath, encoding)

FileSystemManager.readFile 的同步版本,读取文件

参数列表

参数参数类型是否必填说明
filePathString要读取的文件的路径
encodingString指定读取文件的字符编码,默认为 binary

返回值

参数键值类型说明
dataString/ArrayBuffer读取到的文本或二进制数据

FileSystemManager.rename(Object object)

重命名文件,可以把文件从 oldPath 移动到 newPath

参数 Object object

属性键值类型是否必填说明
oldPathString源文件路径,可以是普通文件或目录
newPathString新文件路径
successFunction接口调用成功的回调函
failFunction(Object res)接口调用失败的回调函数
completeFunction接口调用结束的回调函数
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
no such file or directory源文件不存在,或目标文件路径的上层目录不存在
permission denied没有写权限

FileSystemManager.renameSync(oldPath, newPath)

FileSystemManager.rename 的同步版本,重命名文件

参数列表

参数参数类型是否必填说明
oldPathString源文件路径,可以是普通文件或目录
newPathString新文件路径

FileSystemManager.rmdir(Object object)

删除目录

参数 Object object

属性键值类型是否必填说明
dirPathObject要删除的目录路径
recursiveboolean是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。
successFunction接口调用成功的回调函数
failFunction(Object res)接口调用失败的回调函数
completeFunction接口调用结束的回调函数
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
no such file or directory目录不存在
directory not empty目录不为空
fail permission denied指定的 dirPath 路径没有写权限

FileSystemManager.rmdirSync(dirPath, recursive)

FileSystemManager.rmdir 的同步版本,移除目录

参数列表

参数参数类型是否必填说明
dirPathObject要删除的目录路径
recursiveboolean是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。

FileSystemManager.readdir(Object object)

读取目录内文件列表

参数 Object object

属性键值类型是否必填说明
dirPathString要读取的目录路径
successFunction接口调用成功的回调函
failFunction(Object res)接口调用失败的回调函数
completeFunction接口调用结束的回调函数

success回调函数的参数 Object res

属性键值类型说明
filesArray[String]指定目录下的文件名数组。
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
no such file or directory目录不存在
fail not a directorydirPath 不是目录
fail permission denied指定的 filePath 路径没有读权限

FileSystemManager.readdirSync(dirPath)

FileSystemManager.readdir 的同步版本,读取目录

参数列表

参数参数类型是否必填说明
dirPathString要读取的目录路径

返回值

属性键值类型说明
filesArray指定目录下的文件名数组

FileSystemManager.unlink(Object object)

删除文件

参数 Object object

属性键值类型是否必填说明
filePathString要删除的文件路径
successFunction接口调用成功的回调函
failFunction(Object res)接口调用失败的回调函数
completeFunction接口调用结束的回调函数
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
fail permission denied指定的路径没有读权限
no such file or directory文件不存在
fail operation not permitted传入的 filePath 是一个目录

FileSystemManager.unlinkSync(filePath)

FileSystemManager.unlink 的同步版本,删除文件

参数列表

参数参数类型是否必填说明
filePathString要删除的文件路径

FileSystemManager.unzip(Object object)

解压文件

参数 Object object

属性键值类型是否必填说明
zipFilePathString源文件路径,只可以是 zip 压缩文件
targetPathString目标目录路径
successFunction接口调用成功的回调函
failFunction(Object res)接口调用失败的回调函数
completeFunction接口调用结束的回调函数
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
permission denied指定目标文件路径没有写权限
no such file or directory源文件不存在,或目标文件路径的上层目录不存在

FileSystemManager.writeFile(Object object)

写文件异步方式

参数 Object object

属性键值类型是否必填说明
filePathString要写入的文件路径
dataString/ArrayBuffer要写入的文本或二进制数据
encodingString指定写入文件的字符编码 utf8 or binary,默认值为 utf8
appendbool默认为 false,覆盖旧文件
successFunction接口调用成功的回调函
failFunction(Object res)接口调用失败的回调函数,指定目录不存在调用
completeFunction接口调用结束的回调函数
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
no such file or directory指定的 filePath 文件不存在, 或是一个目录
permission denied指定目标文件路径没有写权限

FileSystemManager.writeFileSync(filePath, data, encoding, append)

FileSystemManager.writeFile 的同步版本,写文件

参数列表

参数参数类型是否必填说明
filePathString要写入的文件路径
dataString/ArrayBuffer要写入的文本或二进制数据
encodingString指定写入文件的字符编码 utf8 or binary,默认值为 utf8
appendbool默认为 false,覆盖旧文件

返回值

boolean值,代表是否写入文件成功

FileSystemManager.saveFile(Object object)

保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath 将不可用。

参数 Object object

属性键值类型是否必填说明
tempFilePathString临时存储文件路径
filePathString要存储的文件路径
successFunction接口调用成功的回调函
failFunction(Object res)接口调用失败的回调函数,指定目录不存在调用
completeFunction接口调用结束的回调函数

success回调函数的参数 Object res

属性键值类型说明
savedFilePathString存储后的文件路径
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
tempFilePath file not exist指定的 tempFilePath 找不到文件
permission denied指定目标文件路径没有写权限
no such file or directory上级目录不存在

FileSystemManager.saveFileSync(tempFilePath, filePath)

FileSystemManager.saveFile 的同步版本,保存临时文件到本地。

参数列表

参数键值类型是否必填说明
tempFilePathString临时存储文件路径
filePathString要存储的文件路径

返回值

属性键值类型说明
savedFilePathString存储后的文件路径

FileSystemManager.removeSavedFile(Object object)

删除该小游戏下已保存的本地缓存文件

参数 Object object

属性键值类型是否必填说明
filePathString需要删除的文件路径
successFunction接口调用成功的回调函
failFunction(Object res)接口调用失败的回调函数,指定目录不存在调用
completeFunction接口调用结束的回调函数
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
file not exist指定的路径找不到文件

FileSystemManager.stat(Object object)

获取文件 Stats 对象

参数 Object object

属性键值类型是否必填说明
pathString文件/目录路径
successFunction(Object res)接口调用成功的回调函
failFunction(Object res)接口调用失败的回调函数
completeFunction接口调用结束的回调函数

success回调函数的参数 Object res

属性键值类型说明
statStats一个 Stats 对象
fail回调函数的参数 Object res
属性说明
errMsg错误信息
错误
错误信息说明
permission denied指定的路径没有读权限
no such file or directory文件或目录不存在

Stats|Object FileSystemManager.statSync(string path, boolean recursive)

FileSystemManager.stat 的同步版本, 获取文件 Stats 对象

参数

string path

文件/目录路径

boolean recursive

是否递归获取目录下的每个文件的 Stats 信息

返回值

当 recursive 为 false 时,res.stats 是一个 Stats 对象。当 recursive 为 true 且 path 是一个目录的路径时,res.stats 是一个 Object,key 以 path 为根路径的相对路径,value 是该路径对应的 Stats 对象。

条匹配 "" 的结果

    没有搜索到与 "" 相关的内容