| path | string | Yes | Application sandbox path of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
| callback | AsyncCallback<[Stream](#stream7)> | Yes | Callback invoked when the stream is open asynchronously. |
| callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. |
**Example**
...
...
@@ -2232,7 +2232,7 @@ Synchronously opens a stream based on the file path.
| Type | Description |
| ------------------ | --------- |
| [Stream](#stream7) | Stream opened.|
| [Stream](#stream) | Stream opened.|
**Example**
...
...
@@ -2260,7 +2260,7 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret
| Type | Description |
| --------------------------------- | --------- |
| Promise<[Stream](#stream7)> | Promise used to return the result.|
| Promise<[Stream](#stream)> | Promise used to return the result.|
**Example**
...
...
@@ -2288,7 +2288,7 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous
| fd | number | Yes | File descriptor of the target file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
| callback | AsyncCallback <[Stream](#stream7)> | Yes | Callback invoked when the stream is open asynchronously. |
| callback | AsyncCallback <[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. |
**Example**
...
...
@@ -2319,7 +2319,7 @@ Synchronously opens a stream based on the file descriptor.
The fileManager module provides APIs for accessing and managing user files. It interworks with the underlying file management services to implement media library and external card management, and provides capabilities for applications to query and create user files.
The **fileManager** module provides APIs for accessing and managing user files. It interworks with the underlying file management services to implement media library and external card management, and provides capabilities for applications to query and create user files.
>**NOTE**<br/>
>
...
...
@@ -35,12 +35,10 @@ Obtains information about the root album or directory in asynchronous mode. This
**Example**
```js
filemanager.getRoot().then((fileInfo)=>{
if(Array.isArray(fileInfo)){
for(vari=0;i<fileInfo.length;i++){
console.log("file:"+JSON.stringify(fileInfo));
}
}
filemanager.getRoot().then((fileInfos)=>{
for(vari=0;i<fileInfos.length;i++){
console.log("files:"+JSON.stringify(fileInfos));
}
}).catch((err)=>{
console.log(err)
});
...
...
@@ -69,14 +67,11 @@ Obtains information about the root album or directory in asynchronous mode. This
"name":"local"
}
};
filemanager.getRoot(options,(err,fileInfo)=>{
if(Array.isArray(fileInfo)){
for(vari=0;i<fileInfo.length;i++){
console.log("file:"+JSON.stringify(fileInfo));
}
}
filemanager.getRoot(options,(err,fileInfos)=>{
for(vari=0;i<fileInfos.length;i++){
console.log("files:"+JSON.stringify(fileInfos));
}
});
```
## filemanager.listFile
...
...
@@ -111,18 +106,17 @@ Obtains information about the second-level album or files in asynchronous mode.
**Example**
```js
// Obtain all files in the directory.
// Call listFile() and getRoot() to obtain the file URI.
letmedia_path=""
filemanager.listFile(media_path,"file")
.then((fileInfo)=>{
if(Array.isArray(fileInfo)){
for(vari=0;i<fileInfo.length;i++){
console.log("file:"+JSON.stringify(fileInfo));
}
}
// Obtain all files in the directory. You can use getRoot to obtain the directory URI.