小程序中文件相关api总结

简介:

wx.saveFile(OBJECT)

保存文件到本地。注意:saveFile 会把临时文件移动,因此调用成功后传入的 tempFilePath 将不可用

OBJECT参数说明:

参数名 类型 必填 说明
count Number 否 最多可以选择的图片张数,默认9
sizeType StringArray 否 original 原图,compressed 压缩图,默认二者都有
sourceType StringArray 否 album 从相册选图,camera 使用相机,默认二者都有
success Function 是 成功则返回图片的本地文件路径列表 tempFilePaths
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

success返回参数说明:

参数 说明
savedFilePath 文件的保存路径
wx.chooseImage({
  success: function(res) {
    var tempFilePaths = res.tempFilePaths
    wx.saveFile({
      tempFilePath: tempFilePaths[0],
      success: function(res) {
        var savedFilePath = res.savedFilePath
      }
    })
  }
})

tip: 本地文件存储的大小限制为 10M

wx.getSavedFileList(OBJECT)

获取本地已保存的文件列表

参数名 类型 必填 说明
success Function 否 接口调用成功的回调函数,返回结果见success返回参数说明
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

success返回参数说明:

参数 类型 说明
errMsg String 接口调用结果
fileList Object Array 文件列表

fileList中的项目说明:

键 类型 说明
filePath String 文件的本地路径
createTime Number 文件的保存时的时间戳,从1970/01/01 08:00:00 到当前时间的秒数
size Number 文件大小,单位B
wx.getSavedFileList({
  success: function(res) {
    console.log(res.fileList)
  }
})

wx.getSavedFileInfo(OBJECT)

获取本地文件的文件信息。此接口只能用于获取已保存到本地的文件,若需要获取临时文件信息,请使用 wx.getFileInfo 接口

OBJECT参数说明:

参数名 类型 必填 说明
filePath String 是 文件路径
success Function 否 接口调用成功的回调函数,返回结果见success返回参数说明
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

success返回参数说明:

参数 类型 说明
errMsg String 接口调用结果
size Number 文件大小,单位B
createTime Number 文件保存时的时间戳,从1970/01/01 08:00:00 到该时刻的秒数
wx.getSavedFileInfo({
  filePath: 'wxfile://somefile', //仅做示例用,非真正的文件路径
  success: function(res) {
    console.log(res.size)
    console.log(res.createTime)
  }
})

wx.removeSavedFile(OBJECT)

删除本地存储的文件

OBJECT参数说明:

参数名 类型 必填 说明
filePath String 是 需要删除的文件路径
success Function 否 接口调用成功的回调函数
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)
wx.getSavedFileList({
  success: function(res) {
    if (res.fileList.length > 0){
      wx.removeSavedFile({
        filePath: res.fileList[0].filePath,
        complete: function(res) {
          console.log(res)
        }
      })
    }
  }
})

wx.openDocument(OBJECT)

新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx

OBJECT参数说明:

参数名 类型 必填 说明 最低版本
filePath String 是 文件路径,可通过 downFile 获得
fileType String 否 文件类型,指定文件类型打开文件,有效值 doc, xls, ppt, pdf, docx, xlsx, pptx 1.4.0
success Function 否 接口调用成功的回调函数
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)
wx.downloadFile({
  url: 'http://example.com/somefile.pdf',
  success: function (res) {
    var filePath = res.tempFilePath
    wx.openDocument({
      filePath: filePath,
      success: function (res) {
        console.log('打开文档成功')
      }
    })
  }
})

文件管理器

FileSystemManager:文件管理器。基础库 1.9.9 开始支持,低版本需做兼容处理

方法

FileSystemManager.access(Object object):判断文件/目录是否存在

FileSystemManager.appendFile(Object object):在文件结尾追加内容

FileSystemManager.saveFile(Object object):保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath 将不可用。

FileSystemManager.getSavedFileList():获取该小程序下已保存的本地缓存文件列表

FileSystemManager.removeSavedFile(Object object):删除该小程序下已保存的本地缓存文件

FileSystemManager.copyFile(Object object):复制文件

FileSystemManager.getFileInfo(Object object):获取该小程序下的 本地临时文件 或 本地缓存文件 信息

FileSystemManager.mkdir(Object object):创建目录

FileSystemManager.readdir(Object object):读取目录内文件列表

FileSystemManager.readFile(Object object):读取本地文件内容

FileSystemManager.rename(Object object):重命名文件,可以把文件从 oldPath 移动到 newPath

FileSystemManager.rmdir(Object object):删除目录

Stats FileSystemManager.stat(Object object):获取文件 Stats 对象

FileSystemManager.unlink(Object object):删除文件

FileSystemManager.unzip(Object object):解压文件

FileSystemManager.writeFile(Object object):写文件

FileSystemManager wx.getFileSystemManager()

获取全局唯一的文件管理器。基础库 1.9.9 开始支持,低版本需做兼容处理

返回值

FileSystemManager:文件管理器

FileSystemManager.appendFile(Object object)

在文件结尾追加内容。基础库 2.1.0 开始支持,低版本需做兼容处理

参数

属性 类型 默认值 必填 说明 支持版本
filePath String 是 要追加内容的文件路径
data string/ArrayBuffer 是 要追加的文本或二进制数据
encoding string utf8 否 要追加的文本或二进制数据
success Function 否 指定写入文件的字符编码
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

object.encoding 的合法值

值 说明
ascii
base64
binary
hex
ucs2/ucs-2/utf16le/utf-16le 以小端序读取
utf-8/utf8
latin1

fail 回调函数

属性 类型 说明 支持版本
errMsg String 错误信息

res.errMsg 的合法值

值 说明
fail no such file or directory, open ${filePath} 指定的 filePath 文件不存在
fail illegal operation on a directory, open "${filePath}" 指定的 filePath 是一个已经存在的目录
fail permission denied, open ${dirPath} 指定的 filePath 路径没有写权限
fail sdcard not mounted 指定的 filePath 是一个已经存在的目录

FileSystemManager.access(Object object)

判断文件/目录是否存在。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

属性 类型 默认值 必填 说明 支持版本
path string 是 要判断是否存在的文件/目录路径
success Function 否 指定写入文件的字符编码
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

fail 回调函数

属性 类型 说明 支持版本
errMsg string 错误信息

res.errMsg 的合法值

值 说明
fail no such file or directory ${path} 文件/目录不存在

FileSystemManager.accessSync(string path)

FileSystemManager.access 的同步版本。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

string path:要判断是否存在的文件/目录路径

错误

errMsg 说明
fail no such file or directory ${path} 文件/目录不存在

FileSystemManager.appendFileSync(string filePath, string|ArrayBuffer data, string encoding)

FileSystemManager.appendFile 的同步版本。基础库 2.1.0 开始支持,低版本需做兼容处理

参数

string filePath:要追加内容的文件路径

string|ArrayBuffer data:要追加的文本或二进制数据

string encoding:指定写入文件的字符编码

encoding 的合法值

值 说明
ascii
base64
binary
hex
ucs2/ucs-2/utf16le/utf-16le 以小端序读取
utf-8/utf8
latin1

错误

errMsg 说明
fail no such file or directory ${path} 文件/目录不存在
fail illegal operation on a directory, open "${filePath}" 指定的 filePath 是一个已经存在的目录
fail permission denied, open ${dirPath} 指定的 filePath 路径没有写权限
fail sdcard not mounted 指定的 filePath 是一个已经存在的目录

FileSystemManager.copyFile(Object object)

复制文件。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

属性 类型 默认值 必填 说明 支持版本
srcPath string 是 源文件路径,只可以是普通文件
destPath string 是 目标文件路径
success Function 否 指定写入文件的字符编码
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

fail 回调函数

属性 类型 说明 支持版本
errMsg string 错误信息

res.errMsg 的合法值

值 说明
fail permission denied, copyFile ${srcPath} -> ${destPath} 指定目标文件路径没有写权限
fail no such file or directory, copyFile ${srcPath} -> ${destPath} 源文件不存在,或目标文件路径的上层目录不存在

FileSystemManager.copyFileSync(string srcPath, string destPath)

FileSystemManager.copyFile 的同步版本。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

string srcPath:源文件路径,只可以是普通文件

string destPath:目标文件路径

错误

errMsg 说明
fail permission denied, copyFile ${srcPath} -> ${destPath} 指定目标文件路径没有写权限
fail no such file or directory, copyFile ${srcPath} -> ${destPath} 源文件不存在,或目标文件路径的上层目录不存在

FileSystemManager.getSavedFileList(Object object)

获取该小程序下已保存的本地缓存文件列表。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

属性 类型 默认值 必填 说明 支持版本
success Function 否 指定写入文件的字符编码
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

success 回调函数

参数

属性 类型 说明 支持版本
fileList Object 文件数组,每一项是一个 FileItem

res.fileList 的结构

属性 类型 说明 支持版本
filePath string 本地路径
size number 本地文件大小,以字节为单位
createTime number 文件创建时间

FileSystemManager.getFileInfo(Object object)

获取该小程序下的 本地临时文件 或 本地缓存文件 信息。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

属性 类型 默认值 必填 说明 支持版本
filePath string 是 要读取的文件路径
success Function 否 接口调用成功的回调函数
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

success 回调函数

属性 类型 说明 支持版本
size number 文件大小,以字节为单位

fail 回调函数

属性 类型 说明 支持版本
errMsg string 错误信息

res.errMsg 的合法值

值 说明
fail file not exist 指定的 filePath 找不到文件

FileSystemManager.mkdir(Object object)

创建目录。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

属性 类型 默认值 必填 说明 支持版本
dirPath string 是 创建的目录路径
success Function 否 接口调用成功的回调函数
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

fail 回调函数

属性 类型 说明 支持版本
errMsg string 错误信息

res.errMsg 的合法值

值 说明
fail no such file or directory ${dirPath} 上级目录不存在
fail permission denied, open ${dirPath} 指定的 filePath 路径没有写权限
fail file already exists ${dirPath} 有同名文件或目录

FileSystemManager.mkdirSync(string dirPath)

FileSystemManager.mkdir 的同步版本。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

string dirPath:创建的目录路径

错误

errMsg 说明
fail no such file or directory ${dirPath} 上级目录不存在
fail permission denied, open ${dirPath} 指定的 filePath 路径没有写权限
fail file already exists ${dirPath} 有同名文件或目录

FileSystemManager.removeSavedFile(Object object)

删除该小程序下已保存的本地缓存文件。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

属性 类型 默认值 必填 说明 支持版本
filePath string 是 需要删除的文件路径
success Function 否 接口调用成功的回调函数
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

fail 回调函数

属性 类型 说明 支持版本
errMsg string 错误信息

res.errMsg 的合法值

值 说明
(fail file not exist) 指定的 tempFilePath 找不到文件

string|ArrayBuffer FileSystemManager.readFileSync(string filePath, string encoding)

FileSystemManager.readFile 的同步版本。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

string filePath:要读取的文件的路径

string encoding:指定读取文件的字符编码,如果不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容

encoding 的合法值

值 说明
ascii
base64
binary
hex
ucs2/ucs-2/utf16le/utf-16le 以小程序读取
utf-8/utf8
latin1

返回值

string|ArrayBuffer data:文件内容

错误

errMsg 说明
fail no such file or directory, open ${filePath} 指定的 filePath 所在目录不存在
fail permission denied, open ${dirPath} 指定的 filePath 路径没有读权限

FileSystemManager.renameSync(string oldPath, string newPath)

FileSystemManager.rename 的同步版本。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

string oldPath:源文件路径,可以是普通文件或目录

string newPath:新文件路径

错误

errMsg 说明
fail permission denied, rename ${oldPath} -> ${newPath} 指定源文件或目标文件没有写权限
fail no such file or directory, rename ${oldPath} -> ${newPath} 源文件不存在,或目标文件路径的上层目录不存在

FileSystemManager.rmdirSync(string dirPath)

FileSystemManager.rmdir 的同步版本。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

string dirPath:要删除的目录路径

错误

errMsg 说明
fail no such file or directory ${dirPath} 目录不存在
fail directory not empty 目录不为空
fail permission denied, open ${dirPath} 指定的 dirPath 路径没有写权限

FileSystemManager.readdir(Object object)

读取目录内文件列表。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

属性 类型 默认值 必填 说明 支持版本
dirPath string 是 要读取的目录路径
success Function 否 接口调用成功的回调函数
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

success 回调函数

属性 类型 说明 支持版本
files Array. 指定目录下的文件名数组

fail 回调函数

参数

属性 类型 说明 支持版本
errMsg string 错误信息

res.errMsg 的合法值

值 说明
fail no such file or directory ${dirPath} 目录不存在
fail not a directory ${dirPath} dirPath 不是目录
fail permission denied, open ${dirPath} 指定的 dirPath 路径没有写权限

FileSystemManager.rename(Object object)

重命名文件,可以把文件从 oldPath 移动到 newPath。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

属性 类型 默认值 必填 说明 支持版本
oldPath string 是 源文件路径,可以是普通文件或目录
newPath string 是 新文件路径
success Function 否 接口调用成功的回调函数
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

fail 回调函数

参数

属性 类型 说明 支持版本
errMsg string 错误信息

res.errMsg 的合法值

值 说明
fail permission denied, rename ${oldPath} -> ${newPath} 指定源文件或目标文件没有写权限
fail no such file or directory, rename ${oldPath} -> ${newPath} 源文件不存在,或目标文件路径的上层目录不存在

FileSystemManager.readFile(Object object)

读取本地文件内容。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

属性 类型 默认值 必填 说明 支持版本
filePath string 是 要读取的文件的路径
encoding string 否 指定读取文件的字符编码,如果不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容
success Function 否 接口调用成功的回调函数
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

object.encoding 的合法值

值 说明
ascii
base64
binary
hex
ucs2/ucs-2/utf16le/utf-16le 以小程序读取
utf-8/utf8
latin1

success 回调函数

参数

属性 类型 说明 支持版本
data string/ArrayBuffer 文件内容

fail 回调函数

参数

属性 类型 说明 支持版本
errMsg string 错误信息

res.errMsg 的合法值

值 说明
fail no such file or directory, open ${filePath} 指定的 filePath 所在目录不存在
fail permission denied, open ${dirPath} 指定的 filePath 路径没有读权限

FileSystemManager.rmdir(Object object)

删除目录。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

属性 类型 默认值 必填 说明 支持版本
dirPath string 是 要删除的目录路径
success Function 否 接口调用成功的回调函数
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

fail 回调函数

参数

属性 类型 说明 支持版本
errMsg string 错误信息

res.errMsg 的合法值

值 说明
fail no such file or directory ${dirPath} 目录不存在
fail directory not empty 目录不为空
fail permission denied, open ${dirPath} 指定的 filePath 路径没有读权限

Array. FileSystemManager.readdirSync(string dirPath)

FileSystemManager.readdir 的同步版本。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

string dirPath:要读取的目录路径

返回值

Array. files:指定目录下的文件名数组

错误

errMsg 说明
fail no such file or directory ${dirPath} 目录不存在
fail not a directory ${dirPath} dirPath 不是目录
fail permission denied, open ${dirPath} 指定的 dirPath 路径没有写权限

FileSystemManager.saveFile(Object object)

保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath 将不可用。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

属性 类型 默认值 必填 说明 支持版本
tempFilePath string 是 临时存储文件路径
filePath string 否 要存储的文件路径
success Function 否 接口调用成功的回调函数
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

success 回调函数

属性 类型 说明 支持版本
savedFilePath number 存储后的文件路径

fail 回调函数

属性 类型 说明 支持版本
errMsg string 错误信息

res.errMsg 的合法值

值 说明
fail tempFilePath file not exist 指定的 tempFilePath 找不到文件
fail permission denied, open "${filePath}" 指定的 filePath 路径没有写权限
fail no such file or directory "${dirPath}" 上级目录不存在

number FileSystemManager.saveFileSync(string tempFilePath, string filePath)

FileSystemManager.saveFile 的同步版本。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

string tempFilePath:临时存储文件路径

string filePath:要存储的文件路径

返回值

number savedFilePath:存储后的文件路径

错误

errMsg 说明
fail tempFilePath file not exist 指定的 tempFilePath 找不到文件
fail permission denied, open "${filePath}" 指定的 filePath 路径没有写权限
fail no such file or directory "${dirPath}" 上级目录不存在

Stats FileSystemManager.stat(Object object)

获取文件 Stats 对象。基础库 1.9.9 开始支持,低版本需做兼容处理

属性 类型 默认值 必填 说明 支持版本
path string 是 文件/目录路径
success Function 否 接口调用成功的回调函数
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

success 回调函数

属性 类型 说明 支持版本
stat Stats 一个 Stats 对象

fail 回调函数

属性 类型 说明 支持版本
errMsg string 错误信息

res.errMsg 的合法值

值 说明
fail permission denied, open ${path} 指定的 path 路径没有读权限
fail no such file or directory ${path} 文件不存在

返回值

Stats

Stats FileSystemManager.statSync(string path)

FileSystemManager.stat 的同步版本。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

string path:文件/目录路径

返回值

Stats stat:一个 Stats 对象

错误

errMsg 说明
fail permission denied, open ${path} 指定的 path 路径没有读权限
fail no such file or directory ${path} 文件不存在

Stats

描述文件状态的对象。基础库 1.9.9 开始支持,低版本需做兼容处理

属性

string mode:文件的类型和存取的权限,对应 POSIX stat.st_mode

number size:文件大小,单位:B,对应 POSIX stat.st_size

number lastAccessedTime:文件最近一次被存取或被执行的时间,UNIX 时间戳,对应 POSIX stat.st_atime

number lastModifiedTime:文件最后一次被修改的时间,UNIX 时间戳,对应 POSIX stat.st_mtime

方法

boolean Stats.isDirectory():判断当前文件是否一个目录

boolean Stats.isFile():判断当前文件是否一个普通文件

boolean Stats.isDirectory()

判断当前文件是否一个目录。基础库 1.9.9 开始支持,低版本需做兼容处理

返回值

boolean:表示当前文件是否一个目录

boolean Stats.isFile()

判断当前文件是否一个普通文件。基础库 1.9.9 开始支持,低版本需做兼容处理

返回值

boolean:表示当前文件是否一个普通文件

FileSystemManager.unlink(Object object)

删除文件。基础库 1.9.9 开始支持,低版本需做兼容处理。

参数

属性 类型 默认值 必填 说明 支持版本
filePath string 是 要删除的文件路径
success Function 否 接口调用成功的回调函数
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

fail 回调函数

属性 类型 说明 支持版本
errMsg string 错误信息

res.errMsg 的合法值

值 说明
fail permission denied, open ${path} 指定的 path 路径没有读权限
fail no such file or directory ${path} 文件不存在
fail operation not permitted, unlink ${filePath} 传入的 filePath 是一个目录

FileSystemManager.unzip(Object object)

解压文件。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

属性 类型 默认值 必填 说明 支持版本
zipFilePath string 是 源文件路径,只可以是 zip 压缩文件
targetPath string 是 目标目录路径
success Function 否 接口调用成功的回调函数
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

fail 回调函数

属性 类型 说明 支持版本
errMsg string 错误信息

res.errMsg 的合法值

值 说明
fail permission denied, unzip ${zipFilePath} -> ${destPath} 指定目标文件路径没有写权限
fail no such file or directory, unzip ${zipFilePath} -> "${destPath} 源文件不存在,或目标文件路径的上层目录不存在

FileSystemManager.unlinkSync(string filePath)

FileSystemManager.unlink 的同步版本。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

string filePath:要删除的文件路径

错误

errMsg 说明
fail permission denied, open ${path} 指定的 path 路径没有读权限
fail no such file or directory ${path} 文件不存在
fail operation not permitted, unlink ${filePath} 传入的 filePath 是一个目录

FileSystemManager.writeFile(Object object)

写文件。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

属性 类型 默认值 必填 说明 支持版本
filePath string 是 要写入的文件路径
data string/ArrayBuffer 是 要写入的文本或二进制数据
encoding string utf8 否 指定写入文件的字符编码
success Function 否 接口调用成功的回调函数
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

object.encoding 的合法值

值 说明
ascii
base64
binary
hex
ucs2/ucs-2/utf16le/utf-16le 以小程序读取
utf-8/utf8
latin1

fail 回调函数

属性 类型 说明 支持版本
errMsg string 错误信息

res.errMsg 的合法值

值 说明
fail no such file or directory, open ${filePath} 指定的 filePath 所在目录不存在
fail permission denied, open ${dirPath} 指定的 filePath 路径没有写权限

FileSystemManager.writeFileSync(string filePath, string|ArrayBuffer data, string encoding)

FileSystemManager.writeFile 的同步版本。基础库 1.9.9 开始支持,低版本需做兼容处理

参数

string filePath:要写入的文件路径

string|ArrayBuffer data:要写入的文本或二进制数据

string encoding:指定写入文件的字符编码

encoding 的合法值

值 说明
ascii
base64
binary
hex
ucs2/ucs-2/utf16le/utf-16le 以小程序读取
utf-8/utf8
latin1

错误

值 说明
fail no such file or directory, open ${filePath} 指定的 filePath 所在目录不存在
fail permission denied, open ${dirPath} 指定的 filePath 路径没有写权限
目录
相关文章
|
人工智能 自然语言处理 小程序
微信小程序+淘宝API,无缝购物体验提升复购率!
在电商竞争激烈的当下,微信小程序与淘宝API的整合为商家提供了一条提升用户体验与复购率的创新路径。本文详解其整合原理、实现步骤及优势,助力商家打造无缝购物体验,提升转化效率。
|
监控 Java 应用服务中间件
高级java面试---spring.factories文件的解析源码API机制
【11月更文挑战第20天】Spring Boot是一个用于快速构建基于Spring框架的应用程序的开源框架。它通过自动配置、起步依赖和内嵌服务器等特性,极大地简化了Spring应用的开发和部署过程。本文将深入探讨Spring Boot的背景历史、业务场景、功能点以及底层原理,并通过Java代码手写模拟Spring Boot的启动过程,特别是spring.factories文件的解析源码API机制。
703 2
|
供应链 小程序 API
微信小程序API集成京东库存,移动端销量暴涨!
在数字化时代,微信小程序与京东库存系统集成成为提升移动端销量的关键策略。本文详解如何通过API实现库存实时同步、优化用户体验,推动销量增长50%以上,并结合实际案例与代码示例,为企业提供可落地的解决方案。
|
前端开发 Cloud Native Java
Java||Springboot读取本地目录的文件和文件结构,读取服务器文档目录数据供前端渲染的API实现
博客不应该只有代码和解决方案,重点应该在于给出解决方案的同时分享思维模式,只有思维才能可持续地解决问题,只有思维才是真正值得学习和分享的核心要素。如果这篇博客能给您带来一点帮助,麻烦您点个赞支持一下,还可以收藏起来以备不时之需,有疑问和错误欢迎在评论区指出~
Java||Springboot读取本地目录的文件和文件结构,读取服务器文档目录数据供前端渲染的API实现
|
数据采集 存储 API
Python爬虫结合API接口批量获取PDF文件
Python爬虫结合API接口批量获取PDF文件
|
API 开发者 UED
自学记录鸿蒙API 13:PreviewKit从文件预览到应用开发
通过学习API 13,我深入研究了**PreviewKit(文件预览服务)**。该模块支持快速预览多种文件类型(文本、图片、视频、音频、PDF等),为文件管理类应用提供系统级支持。本文分享了从搭建开发环境到实现单文件和多文件预览的全过程,并介绍了如何构建一个实用的文件预览助手应用。通过实践,不仅掌握了技术细节,还提升了个人开发能力。希望这些经验能为其他开发者带来启发与帮助。
628 10
自学记录鸿蒙API 13:PreviewKit从文件预览到应用开发
|
缓存 小程序 API
微信小程序网络请求与API调用:实现数据交互
本文深入探讨了微信小程序的网络请求与API调用,涵盖`wx.request`的基本用法、常见场景(如获取数据、提交表单、上传和下载文件)及注意事项(如域名配置、HTTPS协议、超时设置和并发限制)。通过一个简单案例,演示了如何实现小程序与服务器的数据交互。掌握这些技能将帮助你构建功能更丰富的应用。
|
监控 小程序 安全
小程序的 API 做了什么处理,能够做到全局变量的隐藏
【10月更文挑战第23天】小程序的 API 通过运行环境隔离、作用域限制、数据绑定机制、事件机制、状态管理、代码封装和模块化、安全策略和权限控制以及运行时监控和检测等多种手段来实现全局变量的隐藏。这些措施共同作用,确保了小程序的安全、稳定和可靠运行,同时也提高了开发效率和代码质量。
404 10
|
Java API 开发者
【Java字节码的掌控者】JDK 22类文件API:解锁Java深层次的奥秘,赋能开发者无限可能!
【9月更文挑战第8天】JDK 22类文件API的引入,为Java开发者们打开了一扇通往Java字节码操控新世界的大门。通过这个API,我们可以更加深入地理解Java程序的底层行为,实现更加高效、可靠和创新的Java应用。虽然目前它还处于预览版阶段,但我们已经可以预见其在未来Java开发中的重要地位。让我们共同期待Java字节码操控新篇章的到来,并积极探索类文件API带来的无限可能!
|
小程序 前端开发 API
微信小程序 - 调用微信 API 回调函数内拿不到 this 问题(解决方案)
本文讨论了在微信小程序中调用API回调函数时无法获取到`this`上下文的问题,并提供了解决方案。在回调函数中,使用一个变量(如`that`)来保存当前的`this`引用,然后在回调内部使用这个变量来访问当前页面的数据和方法。