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
**System capability**: SystemCapability.FileManagement.File.FileIO

A
Annie_wang 已提交
21
**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_wang 已提交
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

A
Annie_wang 已提交
33
**Example**
A
annie_wangli 已提交
34

A
annie_wangli 已提交
35
  ```js
A
Annie_wang 已提交
36
  let path = "/dev";
A
Annie_wang 已提交
37 38 39 40
  statfs.getFreeBytes(path).then(function (number) {
      console.info("getFreeBytes promise successfully:" + number);
  }).catch(function (err) {
      console.info("getFreeBytes failed with error:" + err);
A
annie_wangli 已提交
41
  });
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_wang 已提交
52
**Parameters**
A
annie_wangli 已提交
53 54

  | 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

A
Annie_wang 已提交
59
**Example**
A
annie_wangli 已提交
60

A
annie_wangli 已提交
61
  ```js
A
Annie_wang 已提交
62
  import featureAbility from '@ohos.ability.featureAbility';
A
Annie_wang 已提交
63 64
  let context = featureAbility.getContext();
  context.getFilesDir().then(function (path) {
A
Annie_wang 已提交
65 66
      statfs.getFreeBytes(path, function (err, number) {
          console.info("getFreeBytes callback successfully:" + number);
A
Annie_wang 已提交
67
      });
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
**System capability**: SystemCapability.FileManagement.File.FileIO

A
Annie_wang 已提交
79
**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_wang 已提交
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

A
Annie_wang 已提交
91
**Example**
A
annie_wangli 已提交
92

A
annie_wangli 已提交
93
  ```js
A
Annie_wang 已提交
94
  let path = "/dev";
A
Annie_wang 已提交
95 96 97 98
  statfs.getTotalBytes(path).then(function (number) {
      console.info("getTotalBytes promise successfully:" + number);
  }).catch(function (err) {
      console.info("getTotalBytes failed with error:" + err);
A
annie_wangli 已提交
99
  });
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
**System capability**: SystemCapability.FileManagement.File.FileIO

A
Annie_wang 已提交
110
**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

A
Annie_wang 已提交
117
**Example**
A
annie_wangli 已提交
118

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