| Preferences | put(key: string, value: ValueType): Promise\<void> | Writes data to the **Preferences** instance. The value to write can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.|
| Preferences | get(key: string, defValue: ValueType): Promise\<ValueType> | Obtains data from the **Preferences** instance. The value to read can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.|
| Preferences | getAll(): Promise<Object> | Obtains an **Object** instance that contains all KV pairs in the **Preferences** instance. |
| Preferences | getAll(): Promise\<Object> | Obtains an **Object** instance that contains all KV pairs in the **Preferences** instance. |
| Preferences | delete(key: string): Promise\<void> | Deletes the KV pair of the specified key from the **Preferences** instance. |
### Storing Data Persistently
Call the **flush()** method to write the cached data back to its text file for persistent storage.
Call **flush()** to write the cached data back to its text file for persistent storage.
**Table 4** API for data persistence
...
...
@@ -68,7 +71,7 @@ You can subscribe to data changes. When the value of the subscribed key is chang
### Deleting Data
Use the following APIs to delete a **Preferences** instance or data file.
You can use the following APIs to delete a **Preferences** instance or data file.
**Table 6** APIs for deleting **Preferences**
...
...
@@ -130,7 +133,7 @@ Use the following APIs to delete a **Preferences** instance or data file.
3. Write data.
Use the **preferences.put()** method to write data to the **Preferences** instance.
Use **preferences.put()** to write data to the **Preferences** instance.
```js
letputPromise=preferences.put('startup','auto');
...
...
@@ -143,7 +146,7 @@ Use the following APIs to delete a **Preferences** instance or data file.
4. Read data.
Use the **preferences.get()** method to read data.
@@ -156,7 +159,7 @@ Use the following APIs to delete a **Preferences** instance or data file.
5. Store data persistently.
Use the **flush()** method to flush data from the **Preferences** instance to its file.
Use **flush()** to flush data from the **Preferences** instance to its file.
```js
preferences.flush();
...
...
@@ -190,7 +193,7 @@ Use the following APIs to delete a **Preferences** instance or data file.
7. Delete the specified file.
Use the **deletePreferences** method to delete the **Preferences** instance and its persistent file and backup and corrupted files. After the specified files are deleted, the application cannot use that instance to perform any data operation. Otherwise, data inconsistency will be caused. The deleted data and files cannot be restored.
Use **deletePreferences()** to delete the **Preferences** instance and its persistent file and backup and corrupted files. After the specified files are deleted, the application cannot use that instance to perform any data operation. Otherwise, data inconsistency will be caused. The deleted data and files cannot be restored.