harmony 鸿蒙@ohos.file.storageStatistics (Application Storage Statistics)
@ohos.file.storageStatistics (Application Storage Statistics)
The storageStatistics module provides APIs for obtaining storage space information, including the space of built-in and plug-in memory cards, space occupied by different types of data, and space of application data.
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.
Modules to Import
import { storageStatistics } from '@kit.CoreFileKit';
storageStatistics.getCurrentBundleStats9+
getCurrentBundleStats(): Promise<BundleStats>
Obtains the storage space (in bytes) of this application. This API uses a promise to return the result.
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
Return value
Type | Description |
---|---|
Promise<Bundlestats> | Promise used to return the application storage space obtained. |
Error codes
For details about the error codes, see File Management Error Codes.
ID | Error Message |
---|---|
401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
13600001 | IPC error. |
13900042 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
storageStatistics.getCurrentBundleStats().then((BundleStats: storageStatistics.BundleStats) => {
console.info("getCurrentBundleStats successfully:" + JSON.stringify(BundleStats));
}).catch((err: BusinessError) => {
console.error("getCurrentBundleStats failed with error:"+ JSON.stringify(err));
});
storageStatistics.getCurrentBundleStats9+
getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void
Obtains the storage space (in bytes) of this application. This API uses a promise to return the result.
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<BundleStats> | Yes | Callback used to return the application space obtained. |
Error codes
For details about the error codes, see File Management Error Codes.
ID | Error Message |
---|---|
401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
13600001 | IPC error. |
13900042 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
storageStatistics.getCurrentBundleStats((error: BusinessError, bundleStats: storageStatistics.BundleStats) => {
if (error) {
console.error("getCurrentBundleStats failed with error:" + JSON.stringify(error));
} else {
// Do something.
console.info("getCurrentBundleStats successfully:" + JSON.stringify(bundleStats));
}
});
storageStatistics.getTotalSize15+
getTotalSize(): Promise<number>
Obtains the total space of the built-in storage, in bytes. This API uses a promise to return the result.
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
Return value
Type | Description |
---|---|
Promise<number> | Promise used to return the total built-in storage space obtained. |
Error codes
For details about the error codes, see File Management Error Codes.
ID | Error Message |
---|---|
13600001 | IPC error. |
13900042 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
storageStatistics.getTotalSize().then((number: number) => {
console.info("getTotalSize successfully:" + JSON.stringify(number));
}).catch((err: BusinessError) => {
console.error("getTotalSize failed with error:"+ JSON.stringify(err));
});
storageStatistics.getTotalSize15+
getTotalSize(callback: AsyncCallback<number>): void
Obtains the total space of the built-in storage, in bytes. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<number> | Yes | Callback used to return the built-in storage space obtained. |
Error codes
For details about the error codes, see File Management Error Codes.
ID | Error Message |
---|---|
401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
13600001 | IPC error. |
13900042 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
storageStatistics.getTotalSize((error: BusinessError, number: number) => {
if (error) {
console.error("getTotalSize failed with error:" + JSON.stringify(error));
} else {
// Do something.
console.info("getTotalSize successfully:" + number);
}
});
storageStatistics.getTotalSizeSync15+
getTotalSizeSync(): number
Obtains the total space of the built-in storage, in bytes. This API returns the result synchronously.
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
Return value
Type | Description |
---|---|
number | Built-in storage space obtained. |
Error codes
For details about the error codes, see File Management Error Codes.
ID | Error Message |
---|---|
13600001 | IPC error. |
13900042 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
let number = storageStatistics.getTotalSizeSync();
console.info("getTotalSizeSync successfully:" + JSON.stringify(number));
} catch (err) {
let error: BusinessError = err as BusinessError;
console.error("getTotalSizeSync failed with error:" + JSON.stringify(error));
}
storageStatistics.getFreeSize15+
getFreeSize(): Promise<number>
Obtains the available space of the built-in storage, in bytes. This API uses a promise to return the result.
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
Return value
Type | Description |
---|---|
Promise<number> | Promise used to return the available space of the built-in storage obtained. |
Error codes
For details about the error codes, see File Management Error Codes.
ID | Error Message |
---|---|
13600001 | IPC error. |
13900042 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
storageStatistics.getFreeSize().then((number: number) => {
console.info("getFreeSize successfully:" + JSON.stringify(number));
}).catch((err: BusinessError) => {
console.error("getFreeSize failed with error:" + JSON.stringify(err));
});
storageStatistics.getFreeSize15+
getFreeSize(callback: AsyncCallback<number>): void
Obtains the available space of the built-in storage, in bytes. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<number> | Yes | Callback used to return the available space of the built-in storage obtained. |
Error codes
For details about the error codes, see File Management Error Codes.
ID | Error Message |
---|---|
401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
13600001 | IPC error. |
13900042 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
storageStatistics.getFreeSize((error: BusinessError, number: number) => {
if (error) {
console.error("getFreeSize failed with error:" + JSON.stringify(error));
} else {
// Do something.
console.info("getFreeSize successfully:" + number);
}
});
storageStatistics.getFreeSizeSync15+
getFreeSizeSync(): number
Obtains the available space of the built-in storage, in bytes. This API returns the result synchronously.
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
Return value
Type | Description |
---|---|
number | Available space of the built-in storage obtained. |
Error codes
For details about the error codes, see File Management Error Codes.
ID | Error Message |
---|---|
13600001 | IPC error. |
13900042 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
let number = storageStatistics.getFreeSizeSync();
console.info("getFreeSizeSync successfully:" + JSON.stringify(number));
} catch (err) {
let error: BusinessError = err as BusinessError;
console.error("getFreeSizeSync failed with error:" + JSON.stringify(error));
}
BundleStats9+
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
Name | Type | Mandatory | Description |
---|---|---|---|
appSize | number | Yes | Size of the application installation files, in bytes. |
cacheSize | number | Yes | Size of the application cache files, in bytes. |
dataSize | number | Yes | Size of other files of the application, in bytes. |
你可能感兴趣的鸿蒙文章
harmony 鸿蒙FileShare_PolicyErrorResult
harmony 鸿蒙FileShare_PolicyInfo
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦