js-apis-statfs.md 4.2 KB
Newer Older
A
annie_wangli 已提交
1 2
# statfs

A
Annie_wang 已提交
3
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.
A
annie_wangli 已提交
4

A
Annie_wang 已提交
5 6
> **NOTE**<br>
> 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.
A
Annie_wang 已提交
7

A
annie_wangli 已提交
8 9
## Modules to Import

A
annie_wangli 已提交
10
```js
A
annie_wangli 已提交
11
import statfs from '@ohos.statfs';
A
annie_wangli 已提交
12 13 14 15 16
```
## statfs.getFreeBytes

getFreeBytes(path:string):Promise&lt;number&gt;

A
Annie_wang 已提交
17
Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.
A
annie_wangli 已提交
18

A
annie_wangli 已提交
19 20 21
**System capability**: SystemCapability.FileManagement.File.FileIO

- **Parameters**
A
annie_wangli 已提交
22

A
annie_wangli 已提交
23
  | Name| Type  | Mandatory| Description                        |
A
annie_wangli 已提交
24
  | ------ | ------ | ---- | ---------------------------- |
A
annie_wangli 已提交
25
  | path   | string | Yes  | File path of the file system.|
A
annie_wangli 已提交
26

A
annie_wangli 已提交
27
- Return value
A
annie_wangli 已提交
28

A
annie_wangli 已提交
29
  | Type                 | Description          |
A
annie_wangli 已提交
30
  | --------------------- | -------------- |
A
annie_wangli 已提交
31
  | Promise&lt;number&gt; | Promise used to return the number of free bytes obtained.|
A
annie_wangli 已提交
32 33 34

- Example

A
annie_wangli 已提交
35
  ```js
A
Annie_wang 已提交
36
  let path = "/dev";
A
annie_wangli 已提交
37
  statfs.getFreeBytes(path).then(function (number){
A
Annie_wang 已提交
38
      console.info("getFreeBytes promise successfully:"+ number);
A
annie_wangli 已提交
39 40 41
  }).catch(function(err){
      console.info("getFreeBytes failed with error:"+ err);
  });
A
annie_wangli 已提交
42 43 44 45 46 47
  ```

## statfs.getFreeBytes

getFreeBytes(path:string, callback:AsyncCallback&lt;number&gt;): void

A
Annie_wang 已提交
48
Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a callback to return the result.
A
annie_wangli 已提交
49

A
annie_wangli 已提交
50
**System capability**: SystemCapability.FileManagement.File.FileIO
A
annie_wangli 已提交
51

A
annie_wangli 已提交
52 53 54
- **Parameters**

  | Name  | Type                       | Mandatory| Description                        |
A
annie_wangli 已提交
55
  | -------- | --------------------------- | ---- | ---------------------------- |
A
annie_wangli 已提交
56 57
  | path     | string                      | Yes  | File path of the file system.|
  | callback | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the number of free bytes obtained.|
A
annie_wangli 已提交
58 59 60

- Example

A
annie_wangli 已提交
61
  ```js
A
Annie_wang 已提交
62 63 64 65 66 67
   import featureAbility from '@ohos.ability.featureAbility';
  let context = featureAbility.getContext();
  context.getFilesDir().then(function (path) {
      statfs.getFreeBytes(path, function(err, number){
          console.info("Got free bytes successfully:"+ number);
      });
A
annie_wangli 已提交
68 69 70 71 72
  });
  ```

## statfs.getTotalBytes

A
annie_wangli 已提交
73
getTotalBytes(path: string): Promise&lt;number&gt;
A
annie_wangli 已提交
74

A
Annie_wang 已提交
75
Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.
A
annie_wangli 已提交
76

A
annie_wangli 已提交
77 78 79
**System capability**: SystemCapability.FileManagement.File.FileIO

- **Parameters**
A
annie_wangli 已提交
80

A
annie_wangli 已提交
81
  | Name| Type  | Mandatory| Description                        |
A
annie_wangli 已提交
82
  | ---- | ------ | ---- | ---------------------------- |
A
annie_wangli 已提交
83
  | path | string | Yes  | File path of the file system.|
A
annie_wangli 已提交
84

A
annie_wangli 已提交
85
- Return value
A
annie_wangli 已提交
86

A
annie_wangli 已提交
87
  | Type                 | Description        |
A
annie_wangli 已提交
88
  | --------------------- | ------------ |
A
annie_wangli 已提交
89
  | Promise&lt;number&gt; | Promise used to return the total number of bytes obtained.|
A
annie_wangli 已提交
90 91 92

- Example

A
annie_wangli 已提交
93
  ```js
A
Annie_wang 已提交
94
  let path = "/dev";
A
annie_wangli 已提交
95
  statfs.getTotalBytes(path).then(function (number){
A
Annie_wang 已提交
96
      console.info("getTotalBytes promise successfully:"+ number);
A
annie_wangli 已提交
97 98 99
  }).catch(function(err){
      console.info("getTotalBytes failed with error:"+ err);
  });
A
annie_wangli 已提交
100 101 102 103
  ```

## statfs.getTotalBytes

A
annie_wangli 已提交
104
getTotalBytes(path: string, callback: AsyncCallback&lt;number&gt;): void
A
annie_wangli 已提交
105

A
Annie_wang 已提交
106
Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a callback to return the result.
A
annie_wangli 已提交
107

A
annie_wangli 已提交
108 109 110
**System capability**: SystemCapability.FileManagement.File.FileIO

- **Parameters**
A
annie_wangli 已提交
111

A
annie_wangli 已提交
112
  | Name  | Type                       | Mandatory| Description                        |
A
annie_wangli 已提交
113
  | -------- | --------------------------- | ---- | ---------------------------- |
A
annie_wangli 已提交
114 115
  | path     | string                      | Yes  | File path of the file system.|
  | callback | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the total number of bytes obtained.  |
A
annie_wangli 已提交
116 117 118

- Example

A
annie_wangli 已提交
119
  ```js
A
Annie_wang 已提交
120 121 122 123 124 125
  import featureAbility from '@ohos.ability.featureAbility';
  let context = featureAbility.getContext();
  context.getFilesDir().then(function (path) {
      statfs.getTotalBytes(path, function(err, number){
          console.info("Got total bytes successfully:"+ number);
      });
A
annie_wangli 已提交
126 127
  });
  ```