Application and file system space statistics

API Introduction

For detailed API information, refer to ohos.file.statvfs and ohos.file.storageStatistics.

File System and Application Space Statistics

Module
Interface Name
Function

@ohos.file.storageStatistics
getCurrent…


This content originally appeared on DEV Community and was authored by liu yang

API Introduction

For detailed API information, refer to ohos.file.statvfs and ohos.file.storageStatistics.

File System and Application Space Statistics

Module Interface Name Function
@ohos.file.storageStatistics getCurrentBundleStats Gets the storage size of the current app (in bytes).
@ohos.file.statvfs getFreeSize Gets the remaining space of the specified file system (in bytes).
@ohos.file.statvfs getTotalSize Gets the total space of the specified file system (in bytes).

Application Space Statistics

BundleStats Property Meaning Statistical Path
appSize Size of the app installation file (in bytes). App installation files are stored in: /data/storage/el1/bundle.
cacheSize Size of the app cache files (in bytes). App cache files are stored in: /data/storage/el1/base/cache, /data/storage/el1/base/haps/entry/cache, /data/storage/el2/base/cache, /data/storage/el2/base/haps/entry/cache.
dataSize Size of app file storage (excluding installation and cache files, in bytes). App files include local, distributed, and database files. Local files are stored in: /data/storage/el1/base, /data/storage/el2/base. Distributed files are stored in: /data/storage/el2/distributedfiles. Database files are stored in: /data/storage/el1/database, /data/storage/el2/database.

Development Examples

Getting the Remaining Space of the File System's Data Partition

import { statfs } from '@kit.CoreFileKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

let context = getContext(this) as common.UIAbilityContext;
let path = context.filesDir;
statfs.getFreeSize(path, (err: BusinessError, number: number) => {
  if (err) {
    console.error(`Invoke getFreeSize failed, code is ${err.code}, message is ${err.message}`);
  } else {
    console.info(`Invoke getFreeSize succeeded, size is ${number}`);
  }
});

Getting the Storage Space Size of the Current Application

import { storageStatistics } from '@kit.CoreFileKit';
import { BusinessError } from '@kit.BasicServicesKit';

storageStatistics.getCurrentBundleStats((err: BusinessError, bundleStats: storageStatistics.BundleStats) => {
  if (err) {
    console.error(`Invoke getCurrentBundleStats failed, code is ${err.code}, message is ${err.message}`);
  } else {
    console.info(`Invoke getCurrentBundleStats succeeded, appsize is ${bundleStats.appSize}`);
  }
});


This content originally appeared on DEV Community and was authored by liu yang


Print Share Comment Cite Upload Translate Updates
APA

liu yang | Sciencx (2025-06-29T09:04:41+00:00) Application and file system space statistics. Retrieved from https://www.scien.cx/2025/06/29/application-and-file-system-space-statistics/

MLA
" » Application and file system space statistics." liu yang | Sciencx - Sunday June 29, 2025, https://www.scien.cx/2025/06/29/application-and-file-system-space-statistics/
HARVARD
liu yang | Sciencx Sunday June 29, 2025 » Application and file system space statistics., viewed ,<https://www.scien.cx/2025/06/29/application-and-file-system-space-statistics/>
VANCOUVER
liu yang | Sciencx - » Application and file system space statistics. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/06/29/application-and-file-system-space-statistics/
CHICAGO
" » Application and file system space statistics." liu yang | Sciencx - Accessed . https://www.scien.cx/2025/06/29/application-and-file-system-space-statistics/
IEEE
" » Application and file system space statistics." liu yang | Sciencx [Online]. Available: https://www.scien.cx/2025/06/29/application-and-file-system-space-statistics/. [Accessed: ]
rf:citation
» Application and file system space statistics | liu yang | Sciencx | https://www.scien.cx/2025/06/29/application-and-file-system-space-statistics/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.