title: FileSystemManager.saveFileSync header: develop nav: api

sidebar: FileSystemManager-saveFileSync

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

方法参数:String tempFilePath, String filePath

tempFilePath参数说明:临时存储文件路径。 filePath参数说明:要存储的文件路径。

同步返回参数说明

参数 类型 说明
savedFilePath String 存储后的文件路径

若接口调用失败,会抛出一个标准的Error对象

代码示例

  • 在 js 文件中
  1. Page({
  2. onLoad() {
  3. const fs = swan.getFileSystemManager();
  4. this.fs = fs;
  5. },
  6. saveFileSync() {
  7. try {
  8. let result = this.fs.saveFileSync(
  9. '/usr/temp.txt', // 仅为示例,实际上请传真实临时路径地址,如 swan.downloadFile 的 tempFilePath 返回参数
  10. `${swan.env.USER_DATA_PATH}/`
  11. );
  12. console.log('saveFileSync success', result);
  13. }
  14. catch (err) {
  15. console.log('saveFileSync fail', err);
  16. }
  17. }
  18. });