harmony 鸿蒙@ohos.statfs (statfs)

  • 2022-08-09
  • 浏览 (651)

@ohos.statfs (statfs)

The statfs module provides APIs for obtaining file system information, including the total number of bytes and the number of idle bytes of the file system.

NOTE

  • The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.

  • The APIs provided by this module are deprecated since API version 9. You are advised to use @ohos.file.statvfs.

Modules to Import

import statfs from '@ohos.statfs';

statfs.getFreeBytes

getFreeBytes(path:string):Promise<number>

Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.

System capability: SystemCapability.FileManagement.File.FileIO

Parameters

Name Type Mandatory Description
path string Yes File path of the file system.

Return value

Type Description
Promise<number> Promise used to return the number of free bytes obtained.

Example

  import { BusinessError } from '@ohos.base';
  let path = "/dev";
  statfs.getFreeBytes(path).then((number: number) => {
    console.info("getFreeBytes promise successfully:" + number);
  }).catch((err: BusinessError) => {
    console.info("getFreeBytes failed with error:" + JSON.stringify(err));
  });

statfs.getFreeBytes

getFreeBytes(path:string, callback:AsyncCallback<number>): void

Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a callback to return the result.

System capability: SystemCapability.FileManagement.File.FileIO

Parameters

Name Type Mandatory Description
path string Yes File path of the file system.
callback AsyncCallback<number> Yes Callback invoked to return the number of free bytes obtained.

Example

  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<number>

Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.

System capability: SystemCapability.FileManagement.File.FileIO

Parameters

Name Type Mandatory Description
path string Yes File path of the file system.

Return value

Type Description
Promise<number> Promise used to return the total number of bytes obtained.

Example

  import { BusinessError } from '@ohos.base';
  let path = "/dev";
  statfs.getTotalBytes(path).then((number: number) => {
    console.info("getTotalBytes promise successfully:" + number);
  }).catch((err: BusinessError) => {
    console.info("getTotalBytes failed with error:" + JSON.stringify(err));
  });

statfs.getTotalBytes

getTotalBytes(path: string, callback: AsyncCallback<number>): void

Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a callback to return the result.

System capability: SystemCapability.FileManagement.File.FileIO

Parameters

Name Type Mandatory Description
path string Yes File path of the file system.
callback AsyncCallback<number> Yes Callback invoked to return the total number of bytes obtained.

Example

  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);
      });
  });

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞