• 首页
  • 插件市场
  • 文档
  • XBuilder
  • 开发插件
  • SSL 自动化
  • 更多
    XBuilder
    开发插件
    SSL 自动化
|

开发插件

  • 概述
  • 鸿蒙 HarmonyOS 插件
  • 文件系统
  • 付费说明

文件系统

为了屏蔽系统环境差异与小程序间数据隔离,特制定 fs:// 路径格式的文件系统。

  • 开发插件过程中使用 @ymx/core 提供的 apis.file.* 下的接口对 fs:// 文件进行读、写、删等操作;
  • @ymx/core 提供的 分享、媒体、网络 等均仅支持 fs 类型的文件路径;
  • 如果确实需要使用操作系统接口访问 fs 路径的文件,请使用 apis.file.toUri('fs://...') 接口转换成 file:// 格式的 URI 处理;

鸿蒙示例

import * as ymx from "@ymx/core";
import fileIo from "@ohos.file.fs";

const fsFilePath = 'fs://file/my_dir/my.txt';
let file: fileIo.File | undefined;
try {
  //使用 apis.file.* 接口操作 fs 文件
  await ymx.apis.file.write(fsFilePath, 'hello 世界 😃');

  //将 fs 路径转换为 file:// URI
  const fileUri = ymx.apis.file.toUri(fsFilePath);
  //使用操作系统接口处理 file URI 路径
  file = await fileIo.open(fileUri, fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY);
  await fileIo.write(file.fd, 'hello 世界 😃');
} catch (err) {
  console.error(err);
} finally {
  if (file) {
    try {
      await fileIo.close(file.fd);
    } catch {
    }
  }
}
© 2026 成都七扇门科技有限公司 版权所有
蜀ICP备17005078号-4