鸿蒙开发文件管理:【@ohos.statfs (statfs)】

statfs

该模块提供文件系统相关存储信息的功能,向应用程序提供获取文件系统总字节数、空闲字节数的JS接口。

说明: 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

复制代码
import statfs from '@ohos.statfs';

statfs.getFreeBytes

getFreeBytes(path:string):Promise

异步方法获取指定文件系统空闲字节数,以Promise形式返回结果。

系统能力:SystemCapability.FileManagement.File.FileIO

  • 参数:

    参数名 类型 必填 说明
    path string 需要查询的文件系统的文件路径
  • 返回值:

    类型 说明
    Promise 返回空闲字节数
  • 示例:

    复制代码
    let path = "/dev";
    statfs.getFreeBytes(path).then(function (number){
        console.info("getFreeBytes promise successfully:"+ number);
    }).catch(function(err){
        console.info("getFreeBytes failed with error:"+ err);
    });

statfs.getFreeBytes

getFreeBytes(path:string, callback:AsyncCallback): void

异步方法获取指定文件系统空闲字节数,使用callback形式返回结果。

系统能力:SystemCapability.FileManagement.File.FileIO

  • 参数:

    参数名 类型 必填 说明
    path string 需要查询的文件系统的文件路径
    callback AsyncCallback 异步获取空闲字节数之后的回调
  • 示例:

    复制代码
     import featureAbility from '@ohos.ability.featureAbility';
    let context = featureAbility.getContext();
    context.getFilesDir().then(function (path) {
        statfs.getFreeBytes(path, function(err, number){
            console.info("getFreeBytes callback successfully:"+ number);
        });
    });

statfs.getTotalBytes

getTotalBytes(path: string): Promise

异步方法获取指定文件系统总字节数,以Promise形式返回结果。

系统能力:SystemCapability.FileManagement.File.FileIO

  • 参数:

    参数 类型 必填 说明
    path string 需要查询的文件系统的文件路径
  • 返回值:

    类型 说明
    Promise 返回总字节数
  • 示例:

    复制代码
    let path = "/dev";
    statfs.getTotalBytes(path).then(function (number){
        console.info("getTotalBytes promise successfully:"+ number);
    }).catch(function(err){
        console.info("getTotalBytes failed with error:"+ err);
    });

statfs.getTotalBytes

getTotalBytes(path: string, callback: AsyncCallback): void

异步方法获取指定文件系统总字节数,使用callback形式返回结果。

系统能力:SystemCapability.FileManagement.File.FileIO

  • 参数:

    参数名 类型 必填 说明
    path string 需要查询的文件系统的文件路径
    callback AsyncCallback 异步获取总字节数之后的回调
  • 示例:

    复制代码
    import featureAbility from '@ohos.ability.featureAbility';
    let context = featureAbility.getContext();
    context.getFilesDir().then(function (path) {
        statfs.getTotalBytes(path, function(err, number){
            console.info("getTotalBytes callback successfully:"+ number);
        });
    });
相关推荐
森之鸟6 小时前
DevEco Studio 6.0.0 元服务页面跳转失败
鸿蒙
前端世界6 小时前
HarmonyOS 实战:用 @Observed + @ObjectLink 玩转多组件实时数据更新
华为·harmonyos
zhanshuo7 小时前
HarmonyOS 实战:从输入框到完整表单,教你一步步搞定用户输入处理
harmonyos
zhanshuo7 小时前
在鸿蒙应用中快速接入地图功能:从配置到实战案例全解析
harmonyos
ajassi20007 小时前
开源 Arkts 鸿蒙应用 开发(十六)自定义绘图控件--波形图
华为·开源·harmonyos
前端世界9 小时前
鸿蒙任务调度机制深度解析:优先级、时间片、多核与分布式的流畅秘密
分布式·华为·harmonyos
小小小小小星12 小时前
鸿蒙开发之ArkUI框架进阶:从声明式范式到跨端实战
harmonyos·arkui
鸿蒙小灰12 小时前
鸿蒙开发对象字面量类型标注的问题
harmonyos
鸿蒙先行者13 小时前
鸿蒙Next不再兼容安卓APK,开发者该如何应对?
harmonyos
AI大模型14 小时前
基于 Ollama 本地 LLM 大语言模型实现 ChatGPT AI 聊天系统
程序员·llm·ollama