获取文件管理器
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 3.9.0 | 4.11 | 4.61 |
文件管理器对象,用于操作应用可访问的本地文件空间,在app平台是应用沙盒目录。
可实现目录和文件的创建、删除、改名或改路径、遍历目录、获取文件信息、读写文件。
注意:
DCloud-、DCloud_、uni-、uni_开头的目录和文件是保留目录。开发者自用的文件目录需避免使用这些前缀;
读取文件API受具体设备内存大小限制,为了在老旧设备具备更好的兼容性,请避免一次性读取大文件的情况(建议文件大小不要超过16M);
ReadFileSuccessResult 的data参数以前类型是string,Android平台4.31、iOS平台4.61起为了同时支持arraybuffer,类型改成了‘string | ArrayBuffer’,请在使用时手动as为指定类型;
注意
HBuilderX 4.71+ 涉及如下API调整| 相关 API | 升级前 | 升级后 |
|---|---|---|
stat / statSync | - 返回路径是系统绝对路径 | - 返回路径是相对参数path的相对路径 * 微信小程序规则:当 recursive 为 false 时,res.stats 是一个 Stats 对象。当 recursive 为 true 且 path 是一个目录的路径时,res.stats 是一个 Array,数组的每一项是一个对象,每个对象包含 path 和 stats * uniapp-x规则为避免返回值是联合类型,均返回数组,具体优化如下: --- 当 path = 文件路径,返回数组,仅包含本身stats,返回 stats.path= "" --- 当 path = 目录路径 && recursive = false,返回数组,仅包含本身stats,返回 stats.path= "/" --- 当 path = 目录路径 && recursive = true,返回数组,包含本身stats和其递归子文件stats和目录文件stats |
saveFile / saveFileSync | 参数 filePath - 传入 null:默认保存到 uni.env.USER_DATA_PATH 目录 - 传入文件路径:如果上一级目录存在,保存到传入的路径,如存在则覆盖;如果上一级目录不存在,上上级目录也不存在,则先递归创建再保存 - 传入目录路径:如果存在,保存到filePath/截取tempFilePath的文件名;如果不存在,先创建再保存 - 传入错误路径:比如无权限的路径,返回 error 返回路径 savedFilePath - 返回绝对路径 | 参数 filePath - 传入 null :默认保存到 uni.env.CACHE_PATH/uni-store/ 目录 - 传入错误路径:比如无权限的路径,返回 error - 传入文件路径:如果上一级目录存在,保存到传入的路径,如存在则覆盖;如果上一级目录不存在,上上级目录也不存在,则先递归创建再保存 -传入filePath是目录路径且已存在,则返回错误码 1300021 -传入filePath是文件路径且已存在,则覆盖写入 - 判断传入路径尾部是否带斜线,如xxx/path、 xxx/path/,直接视为写入到path文件,如xxx/path/sub.txt 具体的是写入到具体的文件,path是目录 返回路径 savedFilePath - 使用 unifile:// 路径, 如果参数filePath=null, savedFilePath= unifile://cache/uni-store/xxx; 否则savedFilePath= unifile://cache/xxx/unifile://usr/xxx/unifile://sandbox/xxx 其他 - 成功保存后删除临时文件 |
getSavedFileList | 返回 uni.env.USER_DATA_PATH 目录中的文件列表, 均绝对路径 | 返回 unifile://cache/uni-store/(uni.env.CACHE_PATH/uni-store/) 目录中的文件列表 |
rmdir / rmdirSync | iOS 无法删除空的 uni.env.USER_DATA_PATH、uni.env.CACHE_PATH 目录(系统限制)Android/Harmony 可删除任意目录 | 删除特殊目录,只删除子,保留本身 - uni.env.SANDBOX_PATH - uni.env.CACHE_PATH - uni.env.USER_DATA_PATH - uni.env.ANDROID_INTERNAL_SANDBOX_PATH 其他创建的目录可以删除子和本身 |
copyFile / copyFileSync | 参数 destPath - 传入文件路径:如果上一级目录存在,保存到传入的路径,如存在则覆盖;如果上一级目录不存在,上上级目录也不存在,则先递归创建再保存 - 传入目录路径:如果存在,保存到destPath/截取tempFilePath的文件名;如果不存在,先创建再保存 - 传入错误路径:比如无权限的路径,返回 error | 参数 destPath - 传入错误路径:比如无权限的路径,返回 error - 传入文件路径:如果上一级目录存在,保存到传入的路径,如存在则覆盖;如果上一级目录不存在,上上级目录也不存在,则先递归创建再保存 -传入destPath是目录路径且已存在,则返回错误码 1300021 -传入destPath是文件路径且已存在,则覆盖写入 - 判断传入路径尾部是否带斜线,如xxx/path、 xxx/path/,直接视为写入到path文件,如xxx/path/sub.txt 具体的是写入到具体的文件,path是目录 |
| 类型 |
|---|
| FileSystemManager |
access 判断文件/目录是否存在
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 3.9.0 | 4.11 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | AccessOptions | 是 | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
accessSync FileSystemManager.access 的同步版本
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | 描述 |
|---|---|---|---|---|
| path | string | 是 | 要判断是否存在的文件/目录路径 (本地路径) |
appendFile 在文件结尾追加内容
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | AppendFileOptions | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
appendFileSync FileSystemManager.appendFile 的同步版本
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | 描述 |
|---|---|---|---|---|
| filePath | string | 是 | 要追加内容的文件路径 (本地路径) | |
| data | string | ArrayBuffer | 是 | 要追加的文本或二进制数据,类型为 String 或 ArrayBuffer,Android平台4.31、iOS平台4.61之前前类型是string,Android平台4.31、iOS平台4.61起支持ArrayBuffer | |
| encoding | string | 否 | 指定写入文件的字符编码支持:ascii base64 utf-8,只在 data 类型是 String 时有效 |
close 关闭文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | CloseOptions | 是 | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
closeSync 同步关闭文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | CloseSyncOptions | 是 | |||||||||||
| |||||||||||||
copyFile 复制文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | CopyFileOptions | 是 | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
copyFileSync FileSystemManager.copyFile 的同步版本
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | 描述 |
|---|---|---|---|---|
| srcPath | string | 是 | 源文件路径,支持本地路径 | |
| destPath | string | 是 | 新文件路径,支持本地路径 |
fstat 获取文件的状态信息
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | FStatOptions | 是 | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| stats | Stats | 是 | Stats 对象,包含了文件的状态信息 | ||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
isDirectory 判断当前文件是否一个目录
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.31 | 4.11 | 4.61 |
| 类型 |
|---|
| boolean |
isFile 判断当前文件是否一个普通文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.31 | 4.11 | 4.61 |
| 类型 |
|---|
| boolean |
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fstatSync 同步获取文件的状态信息
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | FStatSyncOptions | 是 | |||||||||||
| |||||||||||||
| 类型 | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Stats | |||||||||||||||||||||||||
|
isDirectory 判断当前文件是否一个目录
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.31 | 4.11 | 4.61 |
| 类型 |
|---|
| boolean |
isFile 判断当前文件是否一个普通文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.31 | 4.11 | 4.61 |
| 类型 |
|---|
| boolean |
ftruncate 对文件内容进行截断操作
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | FTruncateFileOptions | 是 | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ftruncateSync 同步对文件内容进行截断操作
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | FTruncateFileSyncOptions | 是 | ||||||||||||||||
| ||||||||||||||||||
getFileInfo 获取该本地临时文件 或 本地缓存文件 信息
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 3.9.0 | 4.11 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | GetFileInfoOptions | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 |
|---|---|---|---|---|
| digest | string | 是 | 按照传入的 digestAlgorithm 计算得出的的文件摘要 | |
| size | number | 是 | 文件大小,以字节为单位 |
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getSavedFileList 获取该已保存的本地缓存文件列表
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | GetSavedFileListOptions | 是 | |||||||||||||||||||||
| |||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 |
|---|---|---|---|---|
| fileList | Array<string> | 是 | 文件数组。自 4.71 起,返回 unifile:// 协议的路径返回 unifile://cache/uni-store/ (uni.env.CACHE_PATH/uni-store/) 目录中的文件列表 |
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mkdir 创建目录
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 3.9.0 | 4.11 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | MkDirOptions | 是 | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mkdirSync FileSystemManager.mkdir 的同步版本
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | 描述 |
|---|---|---|---|---|
| dirPath | string | 是 | 创建的目录路径 (本地路径) | |
| recursive | boolean | 是 | 是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。 |
open 打开文件,返回文件描述符
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | OpenFileOptions | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 |
|---|---|---|---|---|
| fd | string | 是 | 文件描述符 |
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
openSync 同步打开文件,返回文件描述符
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | OpenFileSyncOptions | 是 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 类型 |
|---|
| string |
readFile 读取本地文件内容
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 3.9.0 | 4.11 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | |||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | ReadFileOptions | 是 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 |
|---|---|---|---|---|
| data | string | ArrayBuffer | 是 | 读取的内容,类型为 String 或 ArrayBuffer,在4.31以前类型是string,Android平台4.31、iOS平台4.61起支持ArrayBuffer |
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
readFileSync FileSystemManager.readFile 的同步版本参数
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | 描述 |
|---|---|---|---|---|
| filePath | string | 是 | 文件路径,支持相对地址和绝对地址,app-android平台支持代码包文件目录 | |
| encoding | string | 否 | base64 / utf-8,指定读取文件的字符编码,(iOS平台4.61及以后、Android平台4.31及以后)如果不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容 |
| 类型 | 描述 |
|---|---|
| string | ArrayBuffer | data文件内容, iOS平台4.61及以后、Android平台4.31及以后支持ArrayBuffer |
read 读文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.31 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | |||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| option | ReadOption | 是 | ||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 |
|---|---|---|---|---|
| arrayBuffer | ArrayBuffer | 是 | 被写入的缓存区的对象,即接口入参的 arrayBuffer | |
| bytesRead | number | 是 | 实际读取的字节数 |
readSync 读文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.31 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| option | ReadSyncOption | 是 | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
| 类型 | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ReadResult | |||||||||||||||
|
readdir 读取目录内文件列表
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 3.9.0 | 4.11 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | ReadDirOptions | 是 | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 |
|---|---|---|---|
| files | Array<string> | 是 |
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
readdirSync FileSystemManager.readdir 的同步版本
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | 描述 |
|---|---|---|---|---|
| dirPath | string | 是 | 要读取的目录路径 (本地路径) |
| 类型 | 必备 |
|---|---|
| Array<string> | 否 |
readZipEntry 读取压缩包内的文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | ReadZipEntryOptions | 是 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 |
|---|---|---|---|---|
| entries | Map<string, ZipFileItem> | 是 | 文件路径 | |
| Map<string, ZipFileItem> | 是 | 已废弃,使用 entries |
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rmdir 删除目录
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 3.9.0 | 4.11 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | RmDirOptions | 是 | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rmdirSync FileSystemManager.rmdir 的同步版本
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | 描述 |
|---|---|---|---|---|
| dirPath | string | 是 | 要删除的目录路径 (本地路径) | |
| recursive | boolean | 是 | 是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。 |
rename 重命名文件。可以把文件从 oldPath 移动到 newPath
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 3.9.0 | 4.11 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | RenameOptions | 是 | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
renameSync FileSystemManager.rename 的同步版本
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | 描述 |
|---|---|---|---|---|
| oldPath | string | 是 | 源文件路径,支持本地路径 | |
| newPath | string | 是 | 新文件路径,支持本地路径 |
removeSavedFile 删除该小程序下已保存的本地缓存文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | RemoveSavedFileOptions | 是 | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
readCompressedFile 读取指定压缩类型的本地文件内容
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | x |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | ReadCompressedFileOptions | 是 | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 |
|---|---|---|---|
| data | string | 是 |
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
readCompressedFileSync 同步读取指定压缩类型的本地文件内容
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | x |
| 名称 | 类型 | 必填 | 兼容性 | 描述 |
|---|---|---|---|---|
| filePath | string | 是 | 要读取的文件的路径 (本地用户文件或代码包文件),app-android平台支持代码包文件目录 | |
| compressionAlgorithm | string | 是 | 文件压缩类型,目前仅支持 'br'。 |
| 类型 |
|---|
| string |
saveFile 保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath 将不可用。
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | SaveFileOptions | 是 | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 |
|---|---|---|---|---|
| savedFilePath | string | 是 | 存储后的文件路径 (本地路径)。自 4.71 起,返回 unifile:// 协议的路径参数filePath=null, savedFilePath= unifile://cache/uni-store/xxx 否则savedFilePath= unifile://cache/xxx/unifile://usr/xxx/unifile://sandbox/xxx |
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
saveFileSync
FileSystemManager.saveFile 的同步版本。自 4.71 起,返回 unifile:// 协议的路径
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | 描述 |
|---|---|---|---|---|
| tempFilePath | string | 是 | 临时存储文件路径 (本地路径) | |
| filePath | string | 否 | 要存储的文件路径 (本地路径),文件已经存在时会直接覆盖 传入不存在的路径\ - App 端自动创建并保存 - 微信小程序会报错 |
| 类型 |
|---|
| string |
stat 获取文件 Stats 对象
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 3.9.0 | 4.11 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | StatOptions | 是 | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| stats | Array<FileStats> | 是 | 微信小程序规则:当 recursive 为 false 时,res.stats 是一个 Stats 对象。当 recursive 为 true 且 path 是一个目录的路径时,res.stats 是一个 Array,数组的每一项是一个对象,每个对象包含 path 和 stats uniapp-x规则为避免返回值是联合类型,均返回数组,具体优化如下: -—— 当 path = 文件路径,返回数组,仅包含本身stats,返回 stats.path= "" -—— 当 path = 目录路径 && recursive = false,返回数组,仅包含本身stats,返回 stats.path= "/" -—— 当 path = 目录路径 && recursive = true,返回数组,包含本身stats和其递归子文件stats和目录文件stats | ||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||
isDirectory 判断当前文件是否一个目录
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.31 | 4.11 | 4.61 |
| 类型 |
|---|
| boolean |
isFile 判断当前文件是否一个普通文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.31 | 4.11 | 4.61 |
| 类型 |
|---|
| boolean |
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
statSync FileSystemManager.stat 的同步版本
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | 描述 |
|---|---|---|---|---|
| path | string | 是 | 文件/目录路径 (本地路径) | |
| recursive | boolean | 是 | 是否递归获取目录下的每个文件的 Stats 信息 |
| 类型 | |||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Array<FileStats> | |||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||
isDirectory 判断当前文件是否一个目录
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.31 | 4.11 | 4.61 |
| 类型 |
|---|
| boolean |
isFile 判断当前文件是否一个普通文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.31 | 4.11 | 4.61 |
| 类型 |
|---|
| boolean |
truncate 对文件内容进行截断操作
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | TruncateFileOptions | 是 | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
truncateSync 对文件内容进行截断操作 (truncate 的同步版本)
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | 描述 |
|---|---|---|---|---|
| filePath | string | 是 | 要截断的文件路径 (本地路径) | |
| length | number | 否 | 截断位置,默认0。如果 length 小于文件长度(字节),则只有前面 length 个字节会保留在文件中,其余内容会被删除;如果 length 大于文件长度,不做处理 |
unlink 删除文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 3.9.0 | 4.11 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | UnLinkOptions | 是 | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
unlinkSync FileSystemManager.unlink 的同步版本
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | 描述 |
|---|---|---|---|---|
| filePath | string | 是 | 文件路径,只支持绝对地址 |
unzip 解压文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | UnzipFileOptions | 是 | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
unzipSync 解压文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS |
|---|---|---|---|---|---|---|
| x | x | x | 5.31 | 5.31 | 7.0 (26.0.0) | 5.31 |
| 名称 | 类型 | 必填 | 兼容性 | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | UnzipSyncOptions | 是 | ||||||||||||||||
| ||||||||||||||||||
| 类型 |
|---|
| boolean |
writeFile 写文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 3.9.0 | 4.11 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | WriteFileOptions | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
writeFileSync FileSystemManager.writeFile 的同步版本
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.51 |
| 名称 | 类型 | 必填 | 兼容性 | 描述 |
|---|---|---|---|---|
| filePath | string | 是 | 文件路径,只支持绝对地址 | |
| data | string | ArrayBuffer | 是 | 要写入的文本或二进制数据,Android平台4.31、iOS平台4.61及以后版本支持ArrayBuffer | |
| encoding | string | 否 | 指定写入文件的字符编码,支持:ascii base64 utf-8, 默认值是utf-8, 仅在 data 类型是 String 时有效 |
write 写入文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | WriteOptions | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 名称 | 类型 | 必备 | 兼容性 | 描述 |
|---|---|---|---|---|
| bytesWritten | number | 是 | 实际被写入到文件中的字节数(注意,被写入的字节数不一定与被写入的字符串字符数相同) |
| 名称 | 类型 | 必备 | 兼容性 | 描述 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| errCode | number | 是 | 错误码 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errSubject | string | 是 | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data | any | 否 | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cause | Error | 否 | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg | string | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
writeSync 同步写入文件
| Web | 微信小程序 | 支付宝小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|---|
| x | 4.41 | 5.31 | 4.13 | 4.61 | 4.61 |
| 名称 | 类型 | 必填 | 兼容性 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | WriteSyncOptions | 是 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 类型 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| WriteResult | ||||||||||
|
app-ios平台4.11版本之前支持的api仅支持在uvue文件中使用文件管理器对象,uts插件中暂不支持; 4.61版本后,所有api都支持在uts插件和uvue文件中使用,具体请查看兼容性
app-android平台API不支持代码包文件目录
app-android平台content:// 路径文件是只读的
示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见
该 API 不支持 Web,请运行 hello uni-app x 到 App 平台体验
<template>
<!-- #ifdef APP -->
<page-intro content="本页演示文件系统 API:递归获取目录、创建文件夹、读写/复制/重命名/删除文件、同步与异步接口等,操作结果在日志区展示。"></page-intro>
<text>显示简易操作日志(可滚动查看),详细日志需真机运行查看</text><button size="mini" @click="data.log=''">清空日志</button>
<scroll-view style="max-height: 300px;">
<text style="margin: 2px; padding: 2px; border: 1px solid #000000;">{{ data.log }}</text>
</scroll-view>
<scroll-view style="flex: 1;">
<!-- #endif -->
<!-- #ifdef MP -->
<text style="margin: 2px; padding: 2px; border: 1px solid #000000;">{{ data.log }}</text>
<!-- #endif -->
<button class="btnstyle" type="primary" @tap="statFileInfoTest"
id="btn-stat-file">递归获取目录files的Stats对象{{data.statFile}}</button>
<button class="btnstyle" type="primary" @tap="mkdirTest" id="btn-mkdir">创建文件夹{{data.mkdirFile}}</button>
<button class="btnstyle" type="primary" @tap="writeFileTest" id="btn-write-file">覆盖写入文件{{data.writeFile}}</button>
<button class="btnstyle" type="primary" @tap="readDirTest" id="btn-read-dir">读取文件夹{{data.readDir}}</button>
<button class="btnstyle" type="primary" @tap="readFileTest" id="btn-read-file">读取文件{{data.readFile}}</button>
<button class="btnstyle" type="primary" @tap="copyFileTest"
id="btn-copy-file">复制文件{{data.copyFromFile}}到{{data.copyToFile}}</button>
<button class="btnstyle" type="primary" @tap="renameFileTest"
id="btn-rename-file">重命名文件{{data.renameFromFile}}到{{data.renameToFile}}</button>
<button class="btnstyle" type="primary" @tap="accessFileTest"
id="btn-access-file">判断文件{{data.accessFile}}是否存在</button>
<button class="btnstyle" type="primary" @tap="unlinkTest" id="btn-unlink-file">删除文件{{data.unlinkFile}}</button>
<button class="btnstyle" type="primary" @tap="unlinkAllFileTest"
id="btn-clear-file">删除文件夹{{data.rmDirFile}}下的所有文件</button>
<button class="btnstyle" type="primary" @tap="rmdirTest" id="btn-remove-dir">删除文件夹{{data.rmDirFile}}</button>
<!-- #ifndef MP-ALIPAY -->
<button class="btnstyle" type="primary" @tap="statFileInfoSyncTest"
id="btn-stat-file-sync">同步递归获取目录files的Stats对象{{data.statFile}}</button>
<button class="btnstyle" type="primary" @tap="appendFileTest"
id="btn-append-file">在文件{{data.readFile}}结尾追加内容</button>
<button class="btnstyle" type="primary" @tap="appendFileSyncTest"
id="btn-append-file-sync">同步在文件{{data.readFile}}结尾追加内容</button>
<!-- #endif -->
<button class="btnstyle" type="primary" @tap="writeFileSyncTest"
id="btn-write-file-sync">同步覆盖写入文件{{data.writeFile}}</button>
<button class="btnstyle" type="primary" @tap="readFileSyncTest"
id="btn-read-file-sync">同步读取文件{{data.readFile}}</button>
<button class="btnstyle" type="primary" @tap="unlinkSyncTest"
id="btn-unlink-file-sync">同步删除文件{{data.unlinkFile}}</button>
<button class="btnstyle" type="primary" @tap="mkdirSyncTest" id="btn-mkdir-sync">同步创建文件夹{{data.mkdirFile}}</button>
<button class="btnstyle" type="primary" @tap="rmdirSyncTest"
id="btn-remove-dir-sync">同步删除文件夹{{data.rmDirFile}}</button>
<button class="btnstyle" type="primary" @tap="readDirSyncTest"
id="btn-read-dir-sync">同步读取文件夹{{data.readDir}}</button>
<!-- #ifndef MP-ALIPAY -->
<button class="btnstyle" type="primary" @tap="accessFileSyncTest"
id="btn-access-file-sync">同步判断文件{{data.accessFile}}是否存在</button>
<button class="btnstyle" type="primary" @tap="renameFileSync"
id="btn-rename-file-sync">同步重命名文件{{data.renameFromFile}}到{{data.renameToFile}}</button>
<!-- #endif -->
<button class="btnstyle" type="primary" @tap="copyFileSyncTest"
id="btn-copy-file-sync">同步复制文件{{data.copyFromFile}}到{{data.copyToFile}}</button>
<!-- #ifndef MP-ALIPAY -->
<button class="btnstyle" type="primary" @tap="removeSavedFileTest" id="btn-remove-saved-file">删除已保存的本地文件</button>
<button class="btnstyle" type="primary" @tap="getSavedFileListTest"
id="btn-getsaved-filelist">获取该已保存的本地缓存文件列表</button>
<!-- #endif -->
<!-- #ifndef MP-ALIPAY -->
<button class="btnstyle" type="primary" @tap="truncateFileTest"
id="btn-truncate-file">对文件{{data.writeFile}}内容进行截断操作</button>
<button class="btnstyle" type="primary" @tap="openFileTest" id="btn-open-file">打开文件{{data.readFile}},返回描述符</button>
<button class="btnstyle" type="primary" @tap="openFileSyncTest('r',true)"
id="btn-open-file-sync">同步打开文件{{data.readFile}},返回描述符</button>
<button class="btnstyle" type="primary" @tap="closeTest" id="btn-close-file">通过文件描述符关闭文件{{data.readFile}}</button>
<button class="btnstyle" type="primary" @tap="closeSyncTest"
id="btn-close-file-sync">通过文件描述符同步关闭文件{{data.readFile}}</button>
<button class="btnstyle" type="primary" @tap="writeTest" id="btn-write">通过文件描述符写入文件{{data.readFile}}</button>
<button class="btnstyle" type="primary" @tap="writeSyncTest"
id="btn-write-sync">同步通过文件描述符写入文件{{data.readFile}}</button>
<button class="btnstyle" type="primary" @tap="fstatTest"
id="btn-fstat-file">通过文件描述符获取{{data.statFile}}的状态信息</button>
<button class="btnstyle" type="primary" @tap="fstatSyncTest"
id="btn-fstat-file-sync">同步通过文件描述符获取{{data.statFile}}的状态信息</button>
<button class="btnstyle" type="primary" @tap="ftruncateFileTest"
id="btn-ftruncate-file">通过文件描述符对文件{{data.writeFile}}内容进行截断</button>
<button class="btnstyle" type="primary" @tap="ftruncateFileSyncTest"
id="btn-ftruncate-file-sync">同步通过文件描述符对文件{{data.writeFile}}内容进行截断</button>
<button class="btnstyle" type="primary" @tap="testWriteReadFileBuffer" id="btn-writereadfile-buffer">写入/读取
ArrayBuffer</button>
<button class="btnstyle" type="primary" @tap="testWriteReadBuffer" id="btn-writeread-buffer">通过文件描述符写入/读取
ArrayBuffer</button>
<button class="btnstyle" type="primary" @tap="testWriteReadSyncBuffer" id="btn-writereadsync-buffer">通过文件描述符同步写入/读取
ArrayBuffer</button>
<button class="btnstyle" type="primary" @tap="testAppendFileBuffer" id="btn-appendfile-buffer">在文件末尾追加
ArrayBuffer</button>
<button class="btnstyle" type="primary" @tap="testAppendFileBufferSync" id="btn-appendfilesync-buffer">同步在文件末尾追加
ArrayBuffer</button>
<!-- #endif -->
<!-- #ifdef APP -->
<button class="btnstyle" type="primary" @tap="copyStaticToFilesTest"
id="btn-copyStatic-file">从static目录复制文件到a目录</button>
<button class="btnstyle" type="primary" @tap="saveFileTest" id="btn-save-file">保存临时文件到本地, filePath=null</button>
<button class="btnstyle" type="primary" @tap="saveFileTest1" id="btn-save-file1">保存临时文件到本地,
filePath=xxx/path.txt</button>
<button class="btnstyle" type="primary" @tap="saveFileTest2" id="btn-save-file2">保存临时文件到本地,
filePath=xxx/path</button>
<button class="btnstyle" type="primary" @tap="saveFileTest3" id="btn-save-file3">保存临时文件到本地,
filePath=xxx/path/</button>
<button class="btnstyle" type="primary" @tap="saveFileAndReadFileTest" id="btn-save-file-read-file">saveFile成功后验证是否可以readFile</button>
<button class="btnstyle" type="primary" @tap="saveFileSyncTest" id="btn-save-file-sync">同步保存临时文件到本地</button>
<button class="btnstyle" type="primary" @tap="unzipFileTest" id="btn-unzip-file">解压文件</button>
<!-- #ifdef VUE3-VAPOR -->
<button class="btnstyle" type="primary" @tap="unzipFileSyncTest" id="btn-unzip-file-sync">同步解压文件</button>
<!-- #endif -->
<!-- #ifndef MP-ALIPAY -->
<button class="btnstyle" type="primary" @tap="truncateFileSyncTest"
id="btn-truncate-file-sync">同步对文件{{data.writeFile}}内容进行截断操作</button>
<button class="btnstyle" type="primary" @tap="readCompressedFileTest"
id="btn-compressed-file">读取指定压缩类型的本地文件内容</button>
<button class="btnstyle" type="primary" @tap="readCompressedFileSyncTest"
id="btn-compressed-file-sync">同步读取指定压缩类型的本地文件内容</button>
<button class="btnstyle" type="primary" @tap="readZipEntry" id="btn-readzip-entry">读取压缩包内的文件</button>
<!-- #endif -->
<button class="btnstyle" type="primary" @tap="testWriteReadFileSyncBuffer" id="btn-writereadfilesync-buffer">同步写入/读取
ArrayBuffer</button>
<button class="btnstyle" type="primary" @tap="testReadFileEncoding('base64')">readFile(content://base64)</button>
<button class="btnstyle" type="primary" @tap="testReadFileEncoding('utf-8')">readFile(content://utf-8)</button>
<button class="btnstyle" type="primary" @tap="testReadFileEncoding('ascii')">readFile(content://ascii)</button>
<button class="btnstyle" type="primary" @tap="testReadFileArrayBuffer()">readFile(content://arraybuffer)</button>
<button class="btnstyle" type="primary"
@tap="testReadFileSyncEncoding('base64')">readFileSync(content://base64)</button>
<button class="btnstyle" type="primary"
@tap="testReadFileSyncEncoding('utf-8')">readFileSync(content://utf-8)</button>
<button class="btnstyle" type="primary"
@tap="testReadFileSyncEncoding('ascii')">readFileSync(content://ascii)</button>
<button class="btnstyle" type="primary"
@tap="testReadFileSyncArrayBuffer()">readFileSync(content://arraybuffer)</button>
<button class="btnstyle" type="primary" @tap="copyFileByContent()">copyFile(content://)</button>
<button class="btnstyle" type="primary" @tap="copyFileSyncByContent()">copyFileSync(content://)</button>
<!-- #endif -->
<button class="btnstyle" type="primary" @tap="gotoExplore()">前往沙盒文件管理器</button>
<button class="btnstyle" type="primary" @tap="gotoTestStatic()">前往Static文件测试</button>
<button class="btnstyle" type="primary" @tap="gotoGetFileInfo()">前往getFileInfo摘要测试</button>
<view style="height: 4px;"></view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="ts">
import { createFileSystemManagerState } from './file-system-manager-state.ts'
import { createBasicAsyncActions } from './file-system-manager-basic-async-actions.ts'
import { createBasicSyncActions } from './file-system-manager-basic-sync.ts'
import { createStorageActions } from './file-system-manager-storage-actions.ts'
import { createFdActions } from './file-system-manager-fd.ts'
import { createBufferActions } from './file-system-manager-buffer.ts'
import { createContentActions } from './file-system-manager-content.ts'
const data = reactive(createFileSystemManagerState())
const {
statFileInfoTest,
copyFileTest,
renameFileTest,
readDirTest,
writeFileTest,
readFileTest,
rmdirTest,
mkdirTest,
accessFileTest,
unlinkTest,
unlinkAllFileTest,
copyStaticToFilesTest,
// #ifndef MP-ALIPAY
appendFileTest,
// #endif
} = createBasicAsyncActions(data)
const {
writeFileSyncTest,
readFileSyncTest,
unlinkSyncTest,
mkdirSyncTest,
rmdirSyncTest,
readDirSyncTest,
copyFileSyncTest,
// #ifndef MP-ALIPAY
accessFileSyncTest,
renameFileSync,
appendFileSyncTest,
statFileInfoSyncTest,
// #endif
} = createBasicSyncActions(data)
const {
unzipFileTest,
unzipFileSyncTest,
// #ifndef MP-ALIPAY
saveFileTest,
saveFileAndReadFileTest,
saveFileTest1,
saveFileTest2,
saveFileTest3,
saveFileSyncTest,
getSavedFileListTest,
truncateFileTest,
truncateFileSyncTest,
readCompressedFileTest,
readCompressedFileSyncTest,
removeSavedFileTest,
// #endif
} = createStorageActions(data, writeFileSyncTest)
const {
// #ifndef MP-ALIPAY
openFileTest,
openFileSyncTest,
closeSyncTest,
closeTest,
writeTest,
writeSyncTest,
fstatTest,
fstatSyncTest,
ftruncateFileTest,
ftruncateFileSyncTest,
readZipEntry,
// #endif
} = createFdActions(data)
const {
testReadFileBuffer,
testWriteReadFileBuffer,
testReadFileSyncBuffer,
testWriteReadFileSyncBuffer,
// #ifndef MP-ALIPAY
testWriteReadBuffer,
testWriteReadSyncBuffer,
testAppendFileBufferSync,
testAppendFileBuffer,
// #endif
} = createBufferActions(
data
// #ifndef MP-ALIPAY
, openFileSyncTest
// #endif
)
const {
// #ifdef APP
testReadFileEncoding,
testReadFileArrayBuffer,
testReadFileSyncEncoding,
testReadFileSyncArrayBuffer,
copyFileByContent,
copyFileSyncByContent,
// #endif
// #ifndef MP-ALIPAY
testOpenFlagWrite,
testWriteLongString,
// #endif
} = createContentActions(data)
const gotoExplore = () => {
uni.navigateTo({
url: "/pages/API/get-file-system-manager/filemanage"
})
}
const gotoTestStatic = () => {
uni.navigateTo({
url: "/pages/API/get-file-system-manager/testStatic"
})
}
const gotoGetFileInfo = () => {
uni.navigateTo({
url: "/pages/API/get-file-system-manager/getFileInfo"
})
}
defineExpose({
data,
// #ifndef MP-ALIPAY
testOpenFlagWrite,
testWriteLongString
// #endif
})
</script>
<style>
.btnstyle {
margin: 4px;
}
</style>
| 名称 | 类型 | 必备 | 描述 |
|---|---|---|---|
| errMsg | string | 是 | 错误信息 |