1e41f4b71Sopenharmony_ci# Obtaining Application and File System Space Statistics
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThis topic describes how to obtain statistics on the space occupied by your application and the free space and total space of a file system.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci## Available APIs
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciFor details about the APIs, see [ohos.file.statvfs](../reference/apis-core-file-kit/js-apis-file-statvfs.md) and [ohos.file.storageStatistics](../reference/apis-core-file-kit/js-apis-file-storage-statistics.md).
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci**Table 1** APIs for application and file system space statistics
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci| Module| API| Description|
12e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
13e41f4b71Sopenharmony_ci| \@ohos.file.storageStatistics | getCurrentBundleStats | Obtains the storage space of the current application, in bytes.| 
14e41f4b71Sopenharmony_ci| \@ohos.file.statvfs | getFreeSize | Obtains the free space of a file system, in bytes.| 
15e41f4b71Sopenharmony_ci| \@ohos.file.statvfs | getTotalSize | Obtains the total space of a file system, in bytes.| 
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci**Table 2** Attributes for application space statistics
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci| BundleStats Attribute| Description| Directory for Statistics| 
20e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
21e41f4b71Sopenharmony_ci| appSize | Size of the application installation files, in bytes.| /data/storage/el1/bundle| 
22e41f4b71Sopenharmony_ci| cacheSize | Size of the application cache files, in bytes.| /data/storage/el1/base/cache<br>/data/storage/el1/base/haps/entry/cache<br>/data/storage/el2/base/cache<br>/data/storage/el2/base/haps/entry/cache| 
23e41f4b71Sopenharmony_ci| dataSize | Size of other files of the application, in bytes.| The files include local files, distributed files, and database files of the application.<br>- Local file directories (parent directories of the **cache** directories):<br>**/data/storage/el1/base**<br>**/data/storage/el2/base**<br>- Distributed file directory:<br>**/data/storage/el2/distributedfiles**<br>- Database directories:<br>**/data/storage/el1/database**<br>**/data/storage/el2/database**| 
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci## Development Example
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci- Obtain the free space of **/data** of the file system.
28e41f4b71Sopenharmony_ci    
29e41f4b71Sopenharmony_ci  ```ts
30e41f4b71Sopenharmony_ci  import { statfs } from '@kit.CoreFileKit';
31e41f4b71Sopenharmony_ci  import { BusinessError } from '@kit.BasicServicesKit';
32e41f4b71Sopenharmony_ci  import { common } from '@kit.AbilityKit';
33e41f4b71Sopenharmony_ci  
34e41f4b71Sopenharmony_ci  let context = getContext(this) as common.UIAbilityContext;
35e41f4b71Sopenharmony_ci  let path = context.filesDir;
36e41f4b71Sopenharmony_ci  statfs.getFreeSize(path, (err: BusinessError, number: number) => {
37e41f4b71Sopenharmony_ci    if (err) {
38e41f4b71Sopenharmony_ci      console.error(`Invoke getFreeSize failed, code is ${err.code}, message is ${err.message}`);
39e41f4b71Sopenharmony_ci    } else {
40e41f4b71Sopenharmony_ci      console.info(`Invoke getFreeSize succeeded, size is ${number}`);
41e41f4b71Sopenharmony_ci    }
42e41f4b71Sopenharmony_ci  });
43e41f4b71Sopenharmony_ci  ```
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci- Obtain the space occupied by the current application.
46e41f4b71Sopenharmony_ci    
47e41f4b71Sopenharmony_ci  ```ts
48e41f4b71Sopenharmony_ci  import { storageStatistics } from '@kit.CoreFileKit';
49e41f4b71Sopenharmony_ci  import { BusinessError } from '@kit.BasicServicesKit';
50e41f4b71Sopenharmony_ci  
51e41f4b71Sopenharmony_ci  storageStatistics.getCurrentBundleStats((err: BusinessError, bundleStats: storageStatistics.BundleStats) => {
52e41f4b71Sopenharmony_ci    if (err) {
53e41f4b71Sopenharmony_ci      console.error(`Invoke getCurrentBundleStats failed, code is ${err.code}, message is ${err.message}`);
54e41f4b71Sopenharmony_ci    } else {
55e41f4b71Sopenharmony_ci      console.info(`Invoke getCurrentBundleStats succeeded, appsize is ${bundleStats.appSize}`);
56e41f4b71Sopenharmony_ci    }
57e41f4b71Sopenharmony_ci  });
58e41f4b71Sopenharmony_ci  ```
59