FileSystemManager.writeFile

版本要求:
BaseKit≥2.4.3
支持平台:
iOSAndroid

方法签名
FileSystemManager.writeFile(params: )

描述

写文件,需要文件读写权限

参数

属性类型必填默认值说明
filePathstring是-要写入的文件路径 (本地路径)
datastring是-要写入的文本数据, 根据encoding编码
encodingstring否"utf8"指定写入文件的字符编码,目前支持【utf8、ascii、base64】, 默认utf8
complete() => void否-接口调用结束的回调函数(调用成功、失败都会执行)
success() => void否-接口调用成功的回调函数
fail(params: Object) => void否-接口调用失败的回调函数
fail 回调参数
属性类型说明
errorMsgstring错误信息
errorCodestring | number错误码
错误扩展

返回值

无

示例代码

import { getFileSystemManager } from '@ray-js/ray'

// 文件操作方法挂在 getFileSystemManager 句柄上(fileId 由句柄自动注入)。
const fm = await getFileSystemManager();

fm.writeFile({
  filePath: "thingfile://usr/ttt_demo.txt",
  data: "hello ttt",
  encoding: "utf8",
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});