鸿蒙开发文件管理:【@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);
        });
    });
相关推荐
1***815319 分钟前
HarmonyOS在智能车载中的娱乐系统
华为·harmonyos·娱乐
4***R24021 分钟前
HarmonyOS在智能车载中的车载娱乐
华为·harmonyos·娱乐
舒一笑1 小时前
GitPulse:让代码的故事自己讲述
git·程序员·intellij idea
食品一少年1 小时前
【DAY1】零基础Flutter 编译开发 鸿蒙HarmonyOS
华为·harmonyos
T***16071 小时前
HarmonyOS在智能家居中的应用
华为·智能家居·harmonyos
马剑威(威哥爱编程)2 小时前
鸿蒙6开发中CANN Kit十大常见问题与解决方案
chrome·华为·harmonyos
h***83932 小时前
HarmonyOS在智能家居中的Huawei Link
华为·智能家居·harmonyos
G_dou_2 小时前
KMP & OpenHarmony 实现二分查找
kotlin·鸿蒙
0***R5154 小时前
HarmonyOS在智能车载中的车载系统
华为·车载系统·harmonyos
F***c3254 小时前
HarmonyOS在智能车载系统中的应用实践
华为·车载系统·harmonyos