Skip to content
Menu
(◍ ´꒳` ◍)

  • Blog
  • Front Page
(◍ ´꒳` ◍)

鸿蒙52文件存储

By admin on 2021年10月11日

文件存储 开发者需要在 Data 中重写 FileDescriptor openFile(Uri uri, String mode)方法来操作文 件:uri 为客户端传入的请求目标路径;mode 为开发者对文件的操作选项,可选方式包含 r(读), w(写), rw(读写)等。 ohos.rpc.MessageParcel 类提供了一个静态方法,用于获取 MessageParcel 实例。开发 者可通过获取到的 MessageParcel 实例,使用 dupFileDescriptor()函数复制待操作文件流的 文件描述符,并将其返回,供远端应用访问文件。 示例:根据传入的 uri 打开对应的文件

private 私有不公开的static final 最后的HiLogLabel LABEL_LOG = new HiLogLabel(HiLog.LOG_APP, 0xD00201, “Data_Log”);
@Override覆盖
public FileDescriptor文件描述符 openFile(Uri uri, String mode) throws投掷 FileNotFoundException 文件源码异常
// 创建 messageParcel
MessageParcel messageParcel = MessageParcel.obtain取得();
File file = new File(uri.getDecodedPathList解码路径表).get(0)); //get(0)是获取 URI 完整字段中查询参数字段。
if (mode == null || !”rw”.equals等于mode)) {
file.setReadOnly();
}
FileInputStream fileIs = new FileInputStream(file);
FileDescriptor 文件描述符fd = null;
try {
fd = fileIs.getFD();
} catch (IOException e) {
HiLog.info(LABEL_LOG, “failed to getFD”);
}
// 绑定文件描述符
return messageParcel.dupFileDescriptor(fd);
}

Category: 鸿蒙

文章导航

pytorchGPU张量运算
鸿蒙53数据库存储

Related Posts

承认平庸-iptables高级-时间模块-20

3月 3, 2023
Read More

鸿蒙32AbilitySlice 路由配置

9月 29, 2021
Read More

鸿蒙11(限定词目录1)

8月 24, 2021
Read More

发表回复 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

近期文章

  • 实施002
  • 实施SQL001
  • 泛微oa001-字段
  • 硬件前端-海康威视摄像头
  • 使用Docker搭建Weblogic服务001

近期评论

    归档

    • 2023年10月
    • 2023年9月
    • 2023年8月
    • 2023年5月
    • 2023年4月
    • 2023年3月
    • 2021年11月
    • 2021年10月
    • 2021年9月
    • 2021年8月
    • 2021年5月

    分类

    • C
    • docker
    • iptable
    • ISIS
    • java
    • k8s
    • liunx
    • OpenCV py
    • ospf
    • solr
    • zabbix
    • 劳动法
    • 周杰伦
    • 格林法则
    • 等保
    • 鸿蒙

    其他操作

    • 登录
    • 条目feed
    • 评论feed
    • WordPress.org
    ©2025 (◍ ´꒳` ◍) | WordPress Theme by Superb WordPress Themes