harmony 鸿蒙@ohos.file.statvfs (File System Space Statistics)
@ohos.file.statvfs (File System Space Statistics)
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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Modules to Import
import statvfs from '@ohos.file.statvfs';
statvfs.getFreeSize
getFreeSize(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. |
Error codes
For details about the error codes, see Basic File IO Error Codes.
Example
import { BusinessError } from '@ohos.base';
let path: string = "/dev";
statvfs.getFreeSize(path).then((number: number) => {
console.info("getFreeSize promise successfully, Size: " + number);
}).catch((err: BusinessError) => {
console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code);
});
statvfs.getFreeSize
getFreeSize(path:string, callback:AsyncCallback<number>): void
Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses an asynchronous 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. |
Error codes
For details about the error codes, see Basic File IO Error Codes.
Example
import { BusinessError } from '@ohos.base';
let path: string = "/dev";
statvfs.getFreeSize(path, (err: BusinessError, number: number) => {
if (err) {
console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("getFreeSize callback successfully, Size: " + number);
}
});
statvfs.getFreeSizeSync10+
getFreeSizeSync(path:string): number
Obtains the number of free bytes of the specified file system. This API returns the result synchronously.
System capability: SystemCapability.FileManagement.File.FileIO
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
path | string | Yes | File path of the file system. |
Return value
Type | Description |
---|---|
number | Promise used to return the number of free bytes obtained. |
Error codes
For details about the error codes, see Basic File IO Error Codes.
Example
let path = "/dev";
let number = statvfs.getFreeSizeSync(path);
console.info("getFreeSize promise successfully, Size: " + number);
statvfs.getTotalSize
getTotalSize(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. |
Error codes
For details about the error codes, see Basic File IO Error Codes.
Example
import { BusinessError } from '@ohos.base';
let path: string = "/dev";
statvfs.getTotalSize(path).then((number: number) => {
console.info("getTotalSize promise successfully, Size: " + number);
}).catch((err: BusinessError) => {
console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code);
});
statvfs.getTotalSize
getTotalSize(path: string, callback: AsyncCallback<number>): void
Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses an asynchronous 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. |
Error codes
For details about the error codes, see Basic File IO Error Codes.
Example
import { BusinessError } from '@ohos.base';
let path: string = "/dev";
statvfs.getTotalSize(path, (err: BusinessError, number: number) => {
if (err) {
console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("getTotalSize promise successfully, Size: " + number);
}
});
statvfs.getTotalSizeSync10+
getTotalSizeSync(path: string): number
Obtains the total number of bytes of the specified file system. This API returns the result synchronously.
System capability: SystemCapability.FileManagement.File.FileIO
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
path | string | Yes | File path of the file system. |
Return value
Type | Description |
---|---|
number | Promise used to return the total number of bytes obtained. |
Error codes
For details about the error codes, see Basic File IO Error Codes.
Example
let path = "/dev";
let number = statvfs.getTotalSizeSync(path);
console.info("getTotalSize promise successfully, Size: " + number);
你可能感兴趣的鸿蒙文章
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)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦