js-apis-environment.md 2.6 KB
Newer Older
E
add doc  
ester.zhou 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
# Environment

> ![icon-note.gif](public_sys-resources/icon-note.gif) **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

```js
import environment from '@ohos.environment';
```

## System Capabilities

SystemCapability.FileManagement.File.Environment

## environment.getStorageDataDir

getStorageDataDir():Promise<string>

Obtains the root directory of the storage. This method uses a promise to return the result.

- Return value

  | Type| Description|
  | --------------------- | ---------------- |
  | Promise<string> | Promise returned with the root directory of the storage.|

- Example

  ```js
  environment.getStorageDataDir().then(function(path){
      console.info("getStorageDataDir successfully:"+ path);
  }).catch(function(error){
      console.info("getStorageDataDir failed with error:"+ error);
  });
  ```

## environment.getStorageDataDir

getStorageDataDir(callback:AsyncCallback<string>):void

Obtains the root directory of the storage. This method uses an asynchronous callback to return the result.

- Parameters

  | Name| Type| Mandatory| Description|
  | -------- | --------------------------- | ---- | -------------------------------- |
  | callback | AsyncCallback<string> | Yes| Asynchronous callback used to return the root directory of the storage.|

- Example

  ```js
  environment.getStorageDataDir(function(error, path){
      // do something
  });
  ```

## environment.getUserDataDir

getUserDataDir():Promise<string>

Obtains the root directory of public files. This method uses a promise to return the result.

- Return value

  | Type| Description|
  | --------------------- | ------------------ |
  | Promise<string> | Promise returned with the root directory of public files.|

- Example

  ```js
  environment.getUserDataDir().then(function(path){
      console.info("getUserDataDir successfully:"+ path);
  }).catch(function(error){
      console.info("getUserDataDir failed with error:"+ error);
  });
  ```

## environment.getUserDataDir

getUserDataDir(callback:AsyncCallback<string>): void

Obtains the root directory of public files. This method uses an asynchronous callback to return the result.

- Parameters

  | Name| Type| Mandatory| Description|
  | -------- | --------------------------- | ---- | -------------------------------- |
  | callback | AsyncCallback<string> | Yes| Asynchronous callback used to return the root directory of public files.|
  
- Example

  ```js
  environment.getUserDataDir(function(error, path){
      // do something
  });
  ```