# FileSystemManager.writeFileSync
写入本地文件。(同步调用)
# 支持说明
应用能力 | Android | iOS | PC | 预览效果 |
---|---|---|---|---|
小程序 | 3.12.0 | 3.11.0 | 3.10.0 | 扫码预览 用BoosHi扫码或PC端点击 |
网页应用 | 待开发 | 待开发 | 待开发 | 待补充 |
# 输入
名称 | 数据类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
filePath | string | 是 | 本地文件路径 | |
data | string/ArrayBuffer | 是 | 要写入的文本或二进制数据 | |
encoding | string | 否 | utf8 | 指定写入文件的字符编码,默认值仅在data为string类型时生效 |
# encoding 的合法值
值 | 说明 | Android | iOS |
---|---|---|---|
ascii | 支持 | 支持 | |
base64 | 支持 | 支持 | |
binary | 支持 | 支持 | |
hex | 支持 | 支持 | |
ucs2/ucs-2/utf16le/utf-16le | 以小端序读取 | 支持 | 支持 |
utf-8/utf8 | 支持 | 支持 | |
latin1 | 支持 | 支持 |
# 输出
继承标准对象输出,无扩展属性
# 代码示例
const fileSystemManager = bz.getFileSystemManager();
const filePath = `bzfile://user/example.txt`;
const res = fileSystemManager.writeFileSync(filePath, "example content", "utf8");
if (!res.errCode) {
console.log("调用成功");
const data = fileSystemManager.readFileSync(filePath);
console.log("写入的内容为:", data);
} else {
console.log("调用失败", err);
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12