鸿蒙开发文件管理:【@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);
        });
    });
相关推荐
康康这名还挺多4 小时前
鸿蒙HarmonyOS list优化一: list 结合 lazyforeach用法
数据结构·list·harmonyos·lazyforeach
晚秋大魔王7 小时前
OpenHarmony 开源鸿蒙南向开发——linux下使用make交叉编译第三方库——nettle库
linux·开源·harmonyos
python算法(魔法师版)11 小时前
.NET 在鸿蒙系统上的适配现状
华为od·华为·华为云·.net·wpf·harmonyos
bestadc12 小时前
鸿蒙 UIAbility组件与UI的数据同步和窗口关闭
harmonyos
枫叶丹413 小时前
【HarmonyOS Next之旅】DevEco Studio使用指南(二十二)
华为·harmonyos·deveco studio·harmonyos next
乱世刀疤17 小时前
深度 |国产操作系统“破茧而出”:鸿蒙电脑填补自主生态空白
华为·harmonyos
沙振宇1 天前
【Web】使用Vue3开发鸿蒙的HelloWorld!
前端·华为·harmonyos
bestadc2 天前
鸿蒙 所有API缩略图鉴
harmonyos
马剑威(威哥爱编程)2 天前
HarmonyOS 5.0 分布式数据协同与跨设备同步
分布式·华为·harmonyos·arkts·harmonyos-next
DONSEE广东东信智能读卡器2 天前
鸿蒙系统使用ArkTS开发语言支持身份证阅读器、社保卡读卡器等调用二次开发SDK
二次开发·sdk·arkts·鸿蒙·身份证阅读器·社保卡读卡器