提交 62d32cd7 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 93c4c64e
# File Management File Management
> **NOTE**<br> > **NOTE**<br>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -22,14 +22,14 @@ Before using the APIs provided by this module to perform operations on files or ...@@ -22,14 +22,14 @@ Before using the APIs provided by this module to perform operations on files or
context.getFilesDir().then((data) => { context.getFilesDir().then((data) => {
path = data; path = data;
}) })
``` ```
## fileio.stat ## fileio.stat
stat(path: string): Promise&lt;Stat&gt; stat(path: string): Promise&lt;Stat&gt;
Obtains file information. This API uses a promise to return the result asynchronously. Obtains file information. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -48,7 +48,7 @@ Obtains file information. This API uses a promise to return the result asynchron ...@@ -48,7 +48,7 @@ Obtains file information. This API uses a promise to return the result asynchron
**Example** **Example**
```js ```js
fileio.stat(path).then(function(stat){ fileio.stat(path).then(function(stat){
console.info("Got file info successfully:"+ JSON.stringify(stat)); console.info("getFileInfo succeed:"+ JSON.stringify(stat));
}).catch(function(err){ }).catch(function(err){
console.info("getFileInfo failed with error:"+ err); console.info("getFileInfo failed with error:"+ err);
}); });
...@@ -107,7 +107,7 @@ Synchronously obtains file information. ...@@ -107,7 +107,7 @@ Synchronously obtains file information.
opendir(path: string): Promise&lt;Dir&gt; opendir(path: string): Promise&lt;Dir&gt;
Opens a file directory. This API uses a promise to return the result asynchronously. Opens a file directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -124,7 +124,7 @@ Opens a file directory. This API uses a promise to return the result asynchronou ...@@ -124,7 +124,7 @@ Opens a file directory. This API uses a promise to return the result asynchronou
**Example** **Example**
```js ```js
fileio.opendir(path).then(function(dir){ fileio.opendir(path).then(function(dir){
console.info("Opened directory successfully:"+ JSON.stringify(dir)); console.info("opendir succeed:"+ JSON.stringify(dir));
}).catch(function(err){ }).catch(function(err){
console.info("opendir failed with error:"+ err); console.info("opendir failed with error:"+ err);
}); });
...@@ -187,7 +187,7 @@ Synchronously opens a directory. ...@@ -187,7 +187,7 @@ Synchronously opens a directory.
access(path: string, mode?: number): Promise&lt;void&gt; access(path: string, mode?: number): Promise&lt;void&gt;
Checks whether the current process can access a file. This API uses a promise to return the result asynchronously. Checks whether the current process can access a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -201,7 +201,7 @@ Checks whether the current process can access a file. This API uses a promise to ...@@ -201,7 +201,7 @@ Checks whether the current process can access a file. This API uses a promise to
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -264,7 +264,7 @@ Synchronously checks whether the current process can access the specified file. ...@@ -264,7 +264,7 @@ Synchronously checks whether the current process can access the specified file.
close(fd: number):Promise&lt;void&gt; close(fd: number):Promise&lt;void&gt;
Closes a file. This API uses a promise to return the result asynchronously. Closes a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -276,7 +276,7 @@ Closes a file. This API uses a promise to return the result asynchronously. ...@@ -276,7 +276,7 @@ Closes a file. This API uses a promise to return the result asynchronously.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -335,14 +335,14 @@ Synchronously closes a file. ...@@ -335,14 +335,14 @@ Synchronously closes a file.
close(): Promise&lt;void&gt; close(): Promise&lt;void&gt;
Closes the stream. This API uses a promise to return the result asynchronously. Closes the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -379,7 +379,7 @@ Closes the stream. This API uses an asynchronous callback to return the result. ...@@ -379,7 +379,7 @@ Closes the stream. This API uses an asynchronous callback to return the result.
copyFile(src:string | number, dest:string | number, mode?:number):Promise&lt;void&gt; copyFile(src:string | number, dest:string | number, mode?:number):Promise&lt;void&gt;
Copies a file. This API uses a promise to return the result asynchronously. Copies a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -393,7 +393,7 @@ Copies a file. This API uses a promise to return the result asynchronously. ...@@ -393,7 +393,7 @@ Copies a file. This API uses a promise to return the result asynchronously.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -454,7 +454,7 @@ Synchronously copies a file. ...@@ -454,7 +454,7 @@ Synchronously copies a file.
mkdir(path:string, mode?: number): Promise&lt;void&gt; mkdir(path:string, mode?: number): Promise&lt;void&gt;
Creates a directory. This API uses a promise to return the result asynchronously. Creates a directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -467,7 +467,7 @@ Creates a directory. This API uses a promise to return the result asynchronously ...@@ -467,7 +467,7 @@ Creates a directory. This API uses a promise to return the result asynchronously
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -526,7 +526,7 @@ Synchronously creates a directory. ...@@ -526,7 +526,7 @@ Synchronously creates a directory.
open(path: string, flags?: number, mode?: number): Promise&lt;number&gt; open(path: string, flags?: number, mode?: number): Promise&lt;number&gt;
Opens a file. This API uses a promise to return the result asynchronously. Opens a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -534,7 +534,7 @@ Opens a file. This API uses a promise to return the result asynchronously. ...@@ -534,7 +534,7 @@ Opens a file. This API uses a promise to return the result asynchronously.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** points to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.| | flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** does not point to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
**Return value** **Return value**
...@@ -545,8 +545,8 @@ Opens a file. This API uses a promise to return the result asynchronously. ...@@ -545,8 +545,8 @@ Opens a file. This API uses a promise to return the result asynchronously.
**Example** **Example**
```js ```js
fileio.open(path, 0o1, 0o0200).then(function(number){ fileio.open(path, 0o1, 0o0200).then(function(number){
console.info("Opened file successfully"); console.info("open file succeed");
}).catch(function(error){ }).catch(function(err){
console.info("open file failed with error:"+ err); console.info("open file failed with error:"+ err);
}); });
``` ```
...@@ -564,7 +564,7 @@ Opens a file. This API uses an asynchronous callback to return the result. ...@@ -564,7 +564,7 @@ Opens a file. This API uses an asynchronous callback to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| flags | number | Yes | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** points to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.| | flags | number | Yes | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** does not point to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
| callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file is open asynchronously. | | callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file is open asynchronously. |
...@@ -588,7 +588,7 @@ Synchronously opens a file. ...@@ -588,7 +588,7 @@ Synchronously opens a file.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** points to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.| | flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** does not point to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o640**: The owner has the read and write permissions, and the user group has the read permission.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.<br>The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.| | mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o640**: The owner has the read and write permissions, and the user group has the read permission.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.<br>The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.|
**Return value** **Return value**
...@@ -618,7 +618,7 @@ read(fd: number, buffer: ArrayBuffer, options?: { ...@@ -618,7 +618,7 @@ read(fd: number, buffer: ArrayBuffer, options?: {
position?: number; position?: number;
}): Promise&lt;ReadOut&gt; }): Promise&lt;ReadOut&gt;
Reads data from a file. This API uses a promise to return the result asynchronously. Reads data from a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -639,11 +639,11 @@ Reads data from a file. This API uses a promise to return the result asynchronou ...@@ -639,11 +639,11 @@ Reads data from a file. This API uses a promise to return the result asynchronou
```js ```js
let fd = fileio.openSync(path, 0o2); let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
fileio.read(fd, buf).then(function(readout){ fileio.read(fd, buf).then(function(readOut){
console.info("Read file data successfully"); console.info("read file data succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(error){ }).catch(function(err){
console.info("read file data failed with error:"+ error); console.info("Failed to read file data. Error:"+ err);
}); });
``` ```
...@@ -674,7 +674,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res ...@@ -674,7 +674,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
fileio.read(fd, buf, function (err, readOut) { fileio.read(fd, buf, function (err, readOut) {
if (readOut) { if (readOut) {
console.info("Read file data successfully"); console.info("read file data succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
} }
}); });
...@@ -717,19 +717,19 @@ Synchronously reads data from a file. ...@@ -717,19 +717,19 @@ Synchronously reads data from a file.
rmdir(path: string): Promise&lt;void&gt; rmdir(path: string): Promise&lt;void&gt;
Deletes a directory. This API uses a promise to return the result asynchronously. Deletes a directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the directory to delete.| | path | string | Yes | Application sandbox path of the directory.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -752,7 +752,7 @@ Deletes a directory. This API uses an asynchronous callback to return the result ...@@ -752,7 +752,7 @@ Deletes a directory. This API uses an asynchronous callback to return the result
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------- | | -------- | ------------------------- | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the directory to delete.| | path | string | Yes | Application sandbox path of the directory.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is deleted asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is deleted asynchronously. |
**Example** **Example**
...@@ -775,7 +775,7 @@ Synchronously deletes a directory. ...@@ -775,7 +775,7 @@ Synchronously deletes a directory.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the directory to delete.| | path | string | Yes | Application sandbox path of the directory.|
**Example** **Example**
```js ```js
...@@ -787,24 +787,24 @@ Synchronously deletes a directory. ...@@ -787,24 +787,24 @@ Synchronously deletes a directory.
unlink(path:string): Promise&lt;void&gt; unlink(path:string): Promise&lt;void&gt;
Deletes a file. This API uses a promise to return the result asynchronously. Deletes a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file to delete.| | path | string | Yes | Application sandbox path of the file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.unlink(path).then(function(){ fileio.unlink(path).then(function(){
console.info("Removed file successfully"); console.info("remove file succeed");
}).catch(function(error){ }).catch(function(error){
console.info("remove file failed with error:"+ error); console.info("remove file failed with error:"+ error);
}); });
...@@ -828,7 +828,7 @@ Deletes a file. This API uses an asynchronous callback to return the result. ...@@ -828,7 +828,7 @@ Deletes a file. This API uses an asynchronous callback to return the result.
**Example** **Example**
```js ```js
fileio.unlink(path, function(err) { fileio.unlink(path, function(err) {
console.info("Removed file successfully"); console.info("remove file succeed");
}); });
``` ```
...@@ -861,7 +861,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: { ...@@ -861,7 +861,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
encoding?: string; encoding?: string;
}): Promise&lt;number&gt; }): Promise&lt;number&gt;
Writes data into a file. This API uses a promise to return the result asynchronously. Writes data into a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -879,9 +879,9 @@ Writes data into a file. This API uses a promise to return the result asynchrono ...@@ -879,9 +879,9 @@ Writes data into a file. This API uses a promise to return the result asynchrono
**Example** **Example**
```js ```js
let fd = fileio.openSync(fpath, 0o100 | 0o2, 0o666); let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
fileio.write(fd, "hello, world").then(function(number){ fileio.write(fd, "hello, world").then(function(number){
console.info("Wrote data to file successfully and size is:"+ number); console.info("write data to file succeed and size is:"+ number);
}).catch(function(err){ }).catch(function(err){
console.info("write data to file failed with error:"+ err); console.info("write data to file failed with error:"+ err);
}); });
...@@ -914,7 +914,7 @@ Writes data into a file. This API uses an asynchronous callback to return the re ...@@ -914,7 +914,7 @@ Writes data into a file. This API uses an asynchronous callback to return the re
let fd = fileio.openSync(path, 0o100 | 0o2, 0o666); let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
fileio.write(fd, "hello, world", function (err, bytesWritten) { fileio.write(fd, "hello, world", function (err, bytesWritten) {
if (bytesWritten) { if (bytesWritten) {
console.info("Wrote data to file successfully and size is:"+ bytesWritten); console.info("write data to file succeed and size is:"+ bytesWritten);
} }
}); });
``` ```
...@@ -956,7 +956,7 @@ Synchronously writes data into a file. ...@@ -956,7 +956,7 @@ Synchronously writes data into a file.
hash(path: string, algorithm: string): Promise&lt;string&gt; hash(path: string, algorithm: string): Promise&lt;string&gt;
Calculates the hash value of a file. This API uses a promise to return the result asynchronously. Calculates the hash value of a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -974,7 +974,7 @@ Calculates the hash value of a file. This API uses a promise to return the resul ...@@ -974,7 +974,7 @@ Calculates the hash value of a file. This API uses a promise to return the resul
**Example** **Example**
```js ```js
fileio.hash(path, "sha256").then(function(str){ fileio.hash(path, "sha256").then(function(str){
console.info("Calculated file hash successfully:"+ str); console.info("calculate file hash succeed:"+ str);
}).catch(function(error){ }).catch(function(error){
console.info("calculate file hash failed with error:"+ err); console.info("calculate file hash failed with error:"+ err);
}); });
...@@ -998,9 +998,9 @@ Calculates the hash value of a file. This API uses an asynchronous callback to r ...@@ -998,9 +998,9 @@ Calculates the hash value of a file. This API uses an asynchronous callback to r
**Example** **Example**
```js ```js
fileio.hash(fpath, "sha256", function(err, hashStr) { fileio.hash(path, "sha256", function(err, hashStr) {
if (hashStr) { if (hashStr) {
console.info("Calculated file hash successfully:"+ hashStr); console.info("calculate file hash succeed:"+ hashStr);
} }
}); });
``` ```
...@@ -1010,7 +1010,7 @@ Calculates the hash value of a file. This API uses an asynchronous callback to r ...@@ -1010,7 +1010,7 @@ Calculates the hash value of a file. This API uses an asynchronous callback to r
chmod(path: string, mode: number):Promise&lt;void&gt; chmod(path: string, mode: number):Promise&lt;void&gt;
Changes file permissions. This API uses a promise to return the result asynchronously. Changes file permissions. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1023,7 +1023,7 @@ Changes file permissions. This API uses a promise to return the result asynchron ...@@ -1023,7 +1023,7 @@ Changes file permissions. This API uses a promise to return the result asynchron
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -1074,7 +1074,7 @@ Synchronously changes file permissions. ...@@ -1074,7 +1074,7 @@ Synchronously changes file permissions.
**Example** **Example**
```js ```js
fileio.chmodSync(fpath, mode); fileio.chmodSync(path, mode);
``` ```
...@@ -1082,7 +1082,7 @@ Synchronously changes file permissions. ...@@ -1082,7 +1082,7 @@ Synchronously changes file permissions.
fstat(fd: number): Promise&lt;Stat&gt; fstat(fd: number): Promise&lt;Stat&gt;
Obtains file information based on the file descriptor. This API uses a promise to return the result asynchronously. Obtains file information based on the file descriptor. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1158,7 +1158,7 @@ Synchronously obtains file information based on the file descriptor. ...@@ -1158,7 +1158,7 @@ Synchronously obtains file information based on the file descriptor.
ftruncate(fd: number, len?: number): Promise&lt;void&gt; ftruncate(fd: number, len?: number): Promise&lt;void&gt;
Truncates a file based on the file descriptor. This API uses a promise to return the result asynchronously. Truncates a file based on the file descriptor. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1171,7 +1171,7 @@ Truncates a file based on the file descriptor. This API uses a promise to return ...@@ -1171,7 +1171,7 @@ Truncates a file based on the file descriptor. This API uses a promise to return
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -1197,7 +1197,7 @@ Truncates a file based on the file descriptor. This API uses an asynchronous cal ...@@ -1197,7 +1197,7 @@ Truncates a file based on the file descriptor. This API uses an asynchronous cal
| -------- | ------------------------- | ---- | ---------------- | | -------- | ------------------------- | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. | | fd | number | Yes | File descriptor of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.| | len | number | Yes | File length, in bytes, after truncation.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback which returns no value. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example** **Example**
```js ```js
...@@ -1231,7 +1231,7 @@ Synchronously truncates a file based on the file descriptor. ...@@ -1231,7 +1231,7 @@ Synchronously truncates a file based on the file descriptor.
truncate(path: string, len?: number): Promise&lt;void&gt; truncate(path: string, len?: number): Promise&lt;void&gt;
Truncates a file based on the file path. This API uses a promise to return the result asynchronously. Truncates a file based on the file path. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1244,12 +1244,12 @@ Truncates a file based on the file path. This API uses a promise to return the r ...@@ -1244,12 +1244,12 @@ Truncates a file based on the file path. This API uses a promise to return the r
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.truncate(path, len).then(function(){ fileio.truncate(path, len).then(function(){
console.info("Truncated file successfully"); console.info("truncate file succeed");
}).catch(function(err){ }).catch(function(err){
console.info("Failed to truncate the file. Error:"+ err); console.info("Failed to truncate the file. Error:"+ err);
}); });
...@@ -1267,9 +1267,9 @@ Truncates a file based on the file path. This API uses an asynchronous callback ...@@ -1267,9 +1267,9 @@ Truncates a file based on the file path. This API uses an asynchronous callback
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------------- | | -------- | ------------------------- | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to truncate. | | path | string | Yes | Application sandbox path of the file to truncate.|
| len | number | Yes | File length, in bytes, after truncation.| | len | number | Yes | File length, in bytes, after truncation.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback which returns no value. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example** **Example**
```js ```js
...@@ -1290,7 +1290,7 @@ Synchronously truncates a file based on the file path. ...@@ -1290,7 +1290,7 @@ Synchronously truncates a file based on the file path.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------- | | ------ | ------ | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to truncate. | | path | string | Yes | Application sandbox path of the file to truncate.|
| len | number | No | File length, in bytes, after truncation.| | len | number | No | File length, in bytes, after truncation.|
**Example** **Example**
...@@ -1307,7 +1307,7 @@ readText(filePath: string, options?: { ...@@ -1307,7 +1307,7 @@ readText(filePath: string, options?: {
encoding?: string; encoding?: string;
}): Promise&lt;string&gt; }): Promise&lt;string&gt;
Reads the text content of a file. This API uses a promise to return the result asynchronously. Reads the text content of a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1325,7 +1325,7 @@ Reads the text content of a file. This API uses a promise to return the result a ...@@ -1325,7 +1325,7 @@ Reads the text content of a file. This API uses a promise to return the result a
**Example** **Example**
```js ```js
fileio.readText(path).then(function(str) { fileio.readText(path).then(function(str) {
console.info("Read text successfully:"+ str); console.info("readText succeed:"+ str);
}).catch(function(err){ }).catch(function(err){
console.info("readText failed with error:"+ err); console.info("readText failed with error:"+ err);
}); });
...@@ -1374,7 +1374,7 @@ Synchronously reads the text of a file. ...@@ -1374,7 +1374,7 @@ Synchronously reads the text of a file.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Application sandbox path of the file to be read. | | filePath | string | Yes | Application sandbox path of the file to read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
**Return value** **Return value**
...@@ -1392,14 +1392,14 @@ Synchronously reads the text of a file. ...@@ -1392,14 +1392,14 @@ Synchronously reads the text of a file.
lstat(path: string): Promise&lt;Stat&gt; lstat(path: string): Promise&lt;Stat&gt;
Obtains link information. This API uses a promise to return the result asynchronously. Obtains link information. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------------- | | ------ | ------ | ---- | -------------------------------------- |
| path | string | Yes | Application sandbox path of the target file, pointing to the link.| | path | string | Yes | Application sandbox path of the target file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
...@@ -1409,7 +1409,7 @@ Obtains link information. This API uses a promise to return the result asynchron ...@@ -1409,7 +1409,7 @@ Obtains link information. This API uses a promise to return the result asynchron
**Example** **Example**
```js ```js
fileio.lstat(path).then(function(stat){ fileio.lstat(path).then(function(stat){
console.info("Got link info successfully:"+ number); console.info("get link status succeed:"+ JSON.stringify(stat));
}).catch(function(err){ }).catch(function(err){
console.info("Failed to obtain the link status. Error:"+ err); console.info("Failed to obtain the link status. Error:"+ err);
}); });
...@@ -1427,7 +1427,7 @@ Obtains link information. This API uses an asynchronous callback to return the r ...@@ -1427,7 +1427,7 @@ Obtains link information. This API uses an asynchronous callback to return the r
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | -------------------------------------- | | -------- | ---------------------------------- | ---- | -------------------------------------- |
| path | string | Yes | Application sandbox path of the target file, pointing to the link.| | path | string | Yes | Application sandbox path of the target file.|
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback used to return the link information obtained. | | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback used to return the link information obtained. |
**Example** **Example**
...@@ -1470,7 +1470,7 @@ read(buffer: ArrayBuffer, options?: { ...@@ -1470,7 +1470,7 @@ read(buffer: ArrayBuffer, options?: {
length?: number; length?: number;
}): Promise&lt;ReadOut&gt; }): Promise&lt;ReadOut&gt;
Reads data from a file. This API uses a promise to return the result asynchronously. Reads data from a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1488,7 +1488,7 @@ Reads data from a file. This API uses a promise to return the result asynchronou ...@@ -1488,7 +1488,7 @@ Reads data from a file. This API uses a promise to return the result asynchronou
**Example** **Example**
```js ```js
fileio.read(new ArrayBuffer(4096)).then(function(readout){ fileio.read(new ArrayBuffer(4096)).then(function(readout){
console.info("Read file data successfully"); console.info("read file data succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(err){ }).catch(function(err){
console.info("Failed to read file data. Error:"+ err); console.info("Failed to read file data. Error:"+ err);
...@@ -1520,7 +1520,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res ...@@ -1520,7 +1520,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
fileio.read(buf, function (err, readOut) { fileio.read(buf, function (err, readOut) {
if (readOut) { if (readOut) {
console.info("Read file data successfully"); console.info("read file data succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
} }
}); });
...@@ -1531,7 +1531,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res ...@@ -1531,7 +1531,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res
rename(oldPath: string, newPath: string): Promise&lt;void&gt; rename(oldPath: string, newPath: string): Promise&lt;void&gt;
Renames a file. This API uses a promise to return the result asynchronously. Renames a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1544,7 +1544,7 @@ Renames a file. This API uses a promise to return the result asynchronously. ...@@ -1544,7 +1544,7 @@ Renames a file. This API uses a promise to return the result asynchronously.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -1602,7 +1602,7 @@ Synchronously renames a file. ...@@ -1602,7 +1602,7 @@ Synchronously renames a file.
fsync(fd: number): Promise&lt;void&gt; fsync(fd: number): Promise&lt;void&gt;
Flushes data of a file to disk. This API uses a promise to return the result asynchronously. Flushes data of a file to disk. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1614,12 +1614,12 @@ Flushes data of a file to disk. This API uses a promise to return the result asy ...@@ -1614,12 +1614,12 @@ Flushes data of a file to disk. This API uses a promise to return the result asy
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.fsync(fd).then(function(){ fileio.fsync(fd).then(function(){
console.info("sync data successfully"); console.info("sync data succeed");
}).catch(function(err){ }).catch(function(err){
console.info("sync data failed with error:"+ err); console.info("sync data failed with error:"+ err);
}); });
...@@ -1663,7 +1663,7 @@ Flushes data of a file to disk in synchronous mode. ...@@ -1663,7 +1663,7 @@ Flushes data of a file to disk in synchronous mode.
**Example** **Example**
```js ```js
fileio.fyncsSync(fd); fileio.fsyncSync(fd);
``` ```
...@@ -1671,7 +1671,7 @@ Flushes data of a file to disk in synchronous mode. ...@@ -1671,7 +1671,7 @@ Flushes data of a file to disk in synchronous mode.
fdatasync(fd: number): Promise&lt;void&gt; fdatasync(fd: number): Promise&lt;void&gt;
Flushes data of a file to disk. This API uses a promise to return the result asynchronously. **fdatasync()** is similar to **fsync()**, but does not flush modified metadata unless that metadata is needed. Flushes data of a file to disk. This API uses a promise to return the result. **fdatasync()** is similar to **fsync()**, but does not flush modified metadata unless that metadata is needed.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1683,7 +1683,7 @@ Flushes data of a file to disk. This API uses a promise to return the result asy ...@@ -1683,7 +1683,7 @@ Flushes data of a file to disk. This API uses a promise to return the result asy
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -1740,7 +1740,7 @@ Synchronizes data in a file in synchronous mode. ...@@ -1740,7 +1740,7 @@ Synchronizes data in a file in synchronous mode.
symlink(target: string, srcPath: string): Promise&lt;void&gt; symlink(target: string, srcPath: string): Promise&lt;void&gt;
Creates a symbolic link based on a path. This API uses a promise to return the result asynchronously. Creates a symbolic link based on the file path. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1753,7 +1753,7 @@ Creates a symbolic link based on a path. This API uses a promise to return the r ...@@ -1753,7 +1753,7 @@ Creates a symbolic link based on a path. This API uses a promise to return the r
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -1769,7 +1769,7 @@ Creates a symbolic link based on a path. This API uses a promise to return the r ...@@ -1769,7 +1769,7 @@ Creates a symbolic link based on a path. This API uses a promise to return the r
symlink(target: string, srcPath: string, callback: AsyncCallback&lt;void&gt;): void symlink(target: string, srcPath: string, callback: AsyncCallback&lt;void&gt;): void
Creates a symbolic link based on a path. This API uses an asynchronous callback to return the result. Creates a symbolic link based on the file path. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1812,7 +1812,7 @@ Synchronously creates a symbolic link based on a specified path. ...@@ -1812,7 +1812,7 @@ Synchronously creates a symbolic link based on a specified path.
chown(path: string, uid: number, gid: number): Promise&lt;void&gt; chown(path: string, uid: number, gid: number): Promise&lt;void&gt;
Changes the file owner based on the file path. This API uses a promise to return the result asynchronously. Changes the file owner based on the file path. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1826,7 +1826,7 @@ Changes the file owner based on the file path. This API uses a promise to return ...@@ -1826,7 +1826,7 @@ Changes the file owner based on the file path. This API uses a promise to return
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -1857,7 +1857,7 @@ Changes the file owner based on the file path. This API uses an asynchronous cal ...@@ -1857,7 +1857,7 @@ Changes the file owner based on the file path. This API uses an asynchronous cal
**Example** **Example**
```js ```js
let stat = fileio.statSync(fpath) let stat = fileio.statSync(path)
fileio.chown(path, stat.uid, stat.gid, function (err){ fileio.chown(path, stat.uid, stat.gid, function (err){
// Do something. // Do something.
}); });
...@@ -1881,7 +1881,7 @@ Synchronously changes the file owner based on its path. ...@@ -1881,7 +1881,7 @@ Synchronously changes the file owner based on its path.
**Example** **Example**
```js ```js
let stat = fileio.statSync(fpath) let stat = fileio.statSync(path)
fileio.chownSync(path, stat.uid, stat.gid); fileio.chownSync(path, stat.uid, stat.gid);
``` ```
...@@ -1890,7 +1890,7 @@ Synchronously changes the file owner based on its path. ...@@ -1890,7 +1890,7 @@ Synchronously changes the file owner based on its path.
mkdtemp(prefix: string): Promise&lt;string&gt; mkdtemp(prefix: string): Promise&lt;string&gt;
Creates a temporary directory. This API uses a promise to return the result asynchronously. Creates a temporary directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1900,9 +1900,9 @@ Creates a temporary directory. This API uses a promise to return the result asyn ...@@ -1900,9 +1900,9 @@ Creates a temporary directory. This API uses a promise to return the result asyn
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value** **Return value**
| Name | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the directory generated.| | Promise&lt;string&gt; | Promise used to return the unique directory generated.|
**Example** **Example**
```js ```js
...@@ -1950,7 +1950,7 @@ Synchronously creates a temporary directory. ...@@ -1950,7 +1950,7 @@ Synchronously creates a temporary directory.
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value** **Return value**
| Name | Description | | Type | Description |
| ------ | ---------- | | ------ | ---------- |
| string | Unique path generated.| | string | Unique path generated.|
...@@ -1964,7 +1964,7 @@ Synchronously creates a temporary directory. ...@@ -1964,7 +1964,7 @@ Synchronously creates a temporary directory.
fchmod(fd: number, mode: number): Promise&lt;void&gt; fchmod(fd: number, mode: number): Promise&lt;void&gt;
Changes file permissions based on the file descriptor. This API uses a promise to return the result asynchronously. Changes file permissions based on the file descriptor. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1975,9 +1975,9 @@ Changes file permissions based on the file descriptor. This API uses a promise t ...@@ -1975,9 +1975,9 @@ Changes file permissions based on the file descriptor. This API uses a promise t
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
**Return value** **Return value**
| Name | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -2036,7 +2036,7 @@ Synchronously changes the file permissions based on the file descriptor. ...@@ -2036,7 +2036,7 @@ Synchronously changes the file permissions based on the file descriptor.
createStream(path: string, mode: string): Promise&lt;Stream&gt; createStream(path: string, mode: string): Promise&lt;Stream&gt;
Opens a file stream based on the file path. This API uses a promise to return the result asynchronously. Opens a file stream based on the file path. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2065,7 +2065,7 @@ Opens a file stream based on the file path. This API uses a promise to return th ...@@ -2065,7 +2065,7 @@ Opens a file stream based on the file path. This API uses a promise to return th
createStream(path: string, mode: string, callback: AsyncCallback&lt;Stream&gt;): void createStream(path: string, mode: string, callback: AsyncCallback&lt;Stream&gt;): void
Opens a stream based on the file path. This API uses an asynchronous callback to return the result. Opens a file stream based on the file path. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2078,7 +2078,7 @@ Opens a stream based on the file path. This API uses an asynchronous callback to ...@@ -2078,7 +2078,7 @@ Opens a stream based on the file path. This API uses an asynchronous callback to
**Example** **Example**
```js ```js
fileio.createStream(path, mode, function(err, stream){ fileio.createStream(path, "r+", function(err, stream){
// Do something. // Do something.
}); });
``` ```
...@@ -2099,7 +2099,7 @@ Synchronously opens a stream based on the file path. ...@@ -2099,7 +2099,7 @@ Synchronously opens a stream based on the file path.
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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).| | mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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).|
**Return value** **Return value**
| Name | Description | | Type | Description |
| ------------------ | --------- | | ------------------ | --------- |
| [Stream](#stream7) | Stream opened.| | [Stream](#stream7) | Stream opened.|
...@@ -2113,7 +2113,7 @@ Synchronously opens a stream based on the file path. ...@@ -2113,7 +2113,7 @@ Synchronously opens a stream based on the file path.
fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt; fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt;
Opens a file stream based on the file descriptor. This API uses a promise to return the result asynchronously. Opens a file stream based on the file descriptor. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2124,13 +2124,14 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret ...@@ -2124,13 +2124,14 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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).| | mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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).|
**Return value** **Return value**
| Name | Description | | Type | Description |
| --------------------------------- | --------- | | --------------------------------- | --------- |
| Promise&lt;[Stream](#stream7)&gt; | Promise used to return the result.| | Promise&lt;[Stream](#stream7)&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
fileio.fdopenStream(fd, mode).then(function(stream){ let fd = fileio.openSync(path);
fileio.fdopenStream(fd, "r+").then(function(stream){
console.info("openStream succeed"); console.info("openStream succeed");
}).catch(function(err){ }).catch(function(err){
console.info("openStream failed with error:"+ err); console.info("openStream failed with error:"+ err);
...@@ -2155,7 +2156,8 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous ...@@ -2155,7 +2156,8 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous
**Example** **Example**
```js ```js
fileio.fdopenStream(fd, mode, function (err, stream) { let fd = fileio.openSync(path);
fileio.fdopenStream(fd, "r+", function (err, stream) {
// Do something. // Do something.
}); });
``` ```
...@@ -2182,6 +2184,7 @@ Synchronously opens a stream based on the file descriptor. ...@@ -2182,6 +2184,7 @@ Synchronously opens a stream based on the file descriptor.
**Example** **Example**
```js ```js
let fd = fileio.openSync(path);
let ss = fileio.fdopenStreamSync(fd, "r+"); let ss = fileio.fdopenStreamSync(fd, "r+");
``` ```
...@@ -2190,7 +2193,7 @@ Synchronously opens a stream based on the file descriptor. ...@@ -2190,7 +2193,7 @@ Synchronously opens a stream based on the file descriptor.
fchown(fd: number, uid: number, gid: number): Promise&lt;void&gt; fchown(fd: number, uid: number, gid: number): Promise&lt;void&gt;
Changes the file owner based on the file descriptor. This API uses a promise to return the result asynchronously. Changes the file owner based on the file descriptor. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2204,7 +2207,7 @@ Changes the file owner based on the file descriptor. This API uses a promise to ...@@ -2204,7 +2207,7 @@ Changes the file owner based on the file descriptor. This API uses a promise to
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -2235,7 +2238,7 @@ Changes the file owner based on the file descriptor. This API uses an asynchrono ...@@ -2235,7 +2238,7 @@ Changes the file owner based on the file descriptor. This API uses an asynchrono
**Example** **Example**
```js ```js
let stat = fileio.statSync(fpath); let stat = fileio.statSync(path);
fileio.fchown(fd, stat.uid, stat.gid, function (err){ fileio.fchown(fd, stat.uid, stat.gid, function (err){
// Do something. // Do something.
}); });
...@@ -2259,7 +2262,7 @@ Synchronously changes the file owner based on the file descriptor. ...@@ -2259,7 +2262,7 @@ Synchronously changes the file owner based on the file descriptor.
**Example** **Example**
```js ```js
let stat = fileio.statSync(fpath); let stat = fileio.statSync(path);
fileio.fchownSync(fd, stat.uid, stat.gid); fileio.fchownSync(fd, stat.uid, stat.gid);
``` ```
...@@ -2268,7 +2271,7 @@ Synchronously changes the file owner based on the file descriptor. ...@@ -2268,7 +2271,7 @@ Synchronously changes the file owner based on the file descriptor.
lchown(path: string, uid: number, gid: number): Promise&lt;void&gt; lchown(path: string, uid: number, gid: number): Promise&lt;void&gt;
Changes the file owner (owner of the symbolic link, not the file referred to by the symbolic link) based on the file path. This API uses a promise to return the result asynchronously. Changes the file owner (owner of the symbolic link, not the file referred to by the symbolic link) based on the file path. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2282,7 +2285,7 @@ Changes the file owner (owner of the symbolic link, not the file referred to by ...@@ -2282,7 +2285,7 @@ Changes the file owner (owner of the symbolic link, not the file referred to by
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise which returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
...@@ -2358,15 +2361,17 @@ Listens for file or directory changes. This API uses an asynchronous callback to ...@@ -2358,15 +2361,17 @@ Listens for file or directory changes. This API uses an asynchronous callback to
| callback | AsyncCallback&lt;number&nbsp;&gt; | Yes | Called each time a change is detected. | | callback | AsyncCallback&lt;number&nbsp;&gt; | Yes | Called each time a change is detected. |
**Return value** **Return value**
| Name | Description | | Type | Description |
| -------------------- | ---------- | | -------------------- | ---------- |
| [Watcher](#watcher7) | Promise used to return the **Watcher** instance.| | [Watcher](#watcher7) | Promise used to return the **Watcher** instance.|
**Example** **Example**
```js ```js
fileio.createWatcher(filename, events, function(watcher){ let filename = path +"/test.txt";
// Do something. fileio.createWatcher(filename, 1, function(number){
console.info("Monitoring times: "+number);
}); });
``` ```
...@@ -2498,7 +2503,7 @@ Checks whether this file is a regular file. ...@@ -2498,7 +2503,7 @@ Checks whether this file is a regular file.
**Example** **Example**
```js ```js
let isFile = fileio.statSync(fpath).isFile(); let isFile = fileio.statSync(path).isFile();
``` ```
...@@ -2549,13 +2554,19 @@ Listens for the changes of a file. You can call the **Watcher.stop()** method sy ...@@ -2549,13 +2554,19 @@ Listens for the changes of a file. You can call the **Watcher.stop()** method sy
stop(): Promise&lt;void&gt; stop(): Promise&lt;void&gt;
Stops the **watcher** instance. This API uses a promise to return the result asynchronously. Stops the **watcher** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Example** **Example**
```js ```js
fileio.stop(); let filename = path +"/test.txt";
let watcher = await fileio.createWatcher(filename, 1, function(number){
console.info("Monitoring times: "+number);
});
watcher.stop().then(function(){
console.info("close watcher succeed");
});
``` ```
...@@ -2574,14 +2585,16 @@ Stops the **watcher** instance. This API uses an asynchronous callback to return ...@@ -2574,14 +2585,16 @@ Stops the **watcher** instance. This API uses an asynchronous callback to return
**Example** **Example**
```js ```js
fileio.stop(function(err){ let filename = path +"/test.txt";
// Do something. let watcher = await fileio.createWatcher(filename, 1, function(number){
console.info("Monitoring times: "+number);
}); });
watcher.stop(function(){
console.info("close watcher succeed");
})
``` ```
## Stream
## Stream<sup>7+</sup>
Provides file stream management. Before calling a method of the **Stream** class, use the **createStream()** method synchronously or asynchronously to create a **Stream** instance. Provides file stream management. Before calling a method of the **Stream** class, use the **createStream()** method synchronously or asynchronously to create a **Stream** instance.
...@@ -2590,7 +2603,7 @@ Provides file stream management. Before calling a method of the **Stream** class ...@@ -2590,7 +2603,7 @@ Provides file stream management. Before calling a method of the **Stream** class
close(): Promise&lt;void&gt; close(): Promise&lt;void&gt;
Closes the stream. This API uses a promise to return the result asynchronously. Closes the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2601,9 +2614,9 @@ Closes the stream. This API uses a promise to return the result asynchronously. ...@@ -2601,9 +2614,9 @@ Closes the stream. This API uses a promise to return the result asynchronously.
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.close().then(function(){ ss.close().then(function(){
console.info("Closed fileStream successfully"); console.info("close fileStream succeed");
}).catch(function(err){ }).catch(function(err){
console.info("close fileStream failed with error:"+ err); console.info("close fileStream failed with error:"+ err);
}); });
...@@ -2625,7 +2638,7 @@ Closes the stream. This API uses an asynchronous callback to return the result. ...@@ -2625,7 +2638,7 @@ Closes the stream. This API uses an asynchronous callback to return the result.
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.close(function (err) { ss.close(function (err) {
// Do something // Do something
}); });
...@@ -2642,7 +2655,7 @@ Synchronously closes the stream. ...@@ -2642,7 +2655,7 @@ Synchronously closes the stream.
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.closeSync(); ss.closeSync();
``` ```
...@@ -2651,7 +2664,7 @@ Synchronously closes the stream. ...@@ -2651,7 +2664,7 @@ Synchronously closes the stream.
flush(): Promise&lt;void&gt; flush(): Promise&lt;void&gt;
Flushes the stream. This API uses a promise to return the result asynchronously. Flushes the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2662,9 +2675,9 @@ Flushes the stream. This API uses a promise to return the result asynchronously. ...@@ -2662,9 +2675,9 @@ Flushes the stream. This API uses a promise to return the result asynchronously.
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.flush().then(function (){ ss.flush().then(function (){
console.info("Flushed stream successfully"); console.info("flush succeed");
}).catch(function(err){ }).catch(function(err){
console.info("flush failed with error:"+ err); console.info("flush failed with error:"+ err);
}); });
...@@ -2686,7 +2699,7 @@ Flushes the stream. This API uses an asynchronous callback to return the result. ...@@ -2686,7 +2699,7 @@ Flushes the stream. This API uses an asynchronous callback to return the result.
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.flush(function (err) { ss.flush(function (err) {
// Do something // Do something
}); });
...@@ -2703,7 +2716,7 @@ Synchronously flushes the stream. ...@@ -2703,7 +2716,7 @@ Synchronously flushes the stream.
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.flushSync(); ss.flushSync();
``` ```
...@@ -2717,7 +2730,7 @@ write(buffer: ArrayBuffer | string, options?: { ...@@ -2717,7 +2730,7 @@ write(buffer: ArrayBuffer | string, options?: {
encoding?: string; encoding?: string;
}): Promise&lt;number&gt; }): Promise&lt;number&gt;
Writes data into the stream. This API uses a promise to return the result asynchronously. Writes data into the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2734,9 +2747,9 @@ Writes data into the stream. This API uses a promise to return the result asynch ...@@ -2734,9 +2747,9 @@ Writes data into the stream. This API uses a promise to return the result asynch
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(fpath, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}).then(function (number){ ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}).then(function (number){
console.info("Wrote data successfully and size is:"+ number); console.info("write succeed and size is:"+ number);
}).catch(function(err){ }).catch(function(err){
console.info("write failed with error:"+ err); console.info("write failed with error:"+ err);
}); });
...@@ -2765,11 +2778,11 @@ Writes data into the stream. This API uses an asynchronous callback to return th ...@@ -2765,11 +2778,11 @@ Writes data into the stream. This API uses an asynchronous callback to return th
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(fpath, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) { ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) {
if (bytesWritten) { if (bytesWritten) {
// Do something // Do something
console.info("Wrote data successfully and size is:"+ bytesWritten); console.info("write succeed and size is:"+ bytesWritten);
} }
}); });
``` ```
...@@ -2801,7 +2814,7 @@ Synchronously writes data into the stream. ...@@ -2801,7 +2814,7 @@ Synchronously writes data into the stream.
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(fpath,"r+"); let ss= fileio.createStreamSync(path,"r+");
let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}); let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'});
``` ```
...@@ -2814,7 +2827,7 @@ read(buffer: ArrayBuffer, options?: { ...@@ -2814,7 +2827,7 @@ read(buffer: ArrayBuffer, options?: {
length?: number; length?: number;
}): Promise&lt;ReadOut&gt; }): Promise&lt;ReadOut&gt;
Reads data from the stream. This API uses a promise to return the result asynchronously. Reads data from the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2831,9 +2844,9 @@ Reads data from the stream. This API uses a promise to return the result asynchr ...@@ -2831,9 +2844,9 @@ Reads data from the stream. This API uses a promise to return the result asynchr
**Example** **Example**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(path, "r+");
ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){ ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){
console.info("Read data successfully"); console.info("read data succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(err){ }).catch(function(err){
console.info("read data failed with error:"+ err); console.info("read data failed with error:"+ err);
...@@ -2862,10 +2875,10 @@ Reads data from the stream. This API uses an asynchronous callback to return the ...@@ -2862,10 +2875,10 @@ Reads data from the stream. This API uses an asynchronous callback to return the
**Example** **Example**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(path, "r+");
ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) { ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) {
if (readOut) { if (readOut) {
console.info("Read data successfully"); console.info("read data succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
} }
}); });
...@@ -2899,7 +2912,7 @@ Synchronously reads data from the stream. ...@@ -2899,7 +2912,7 @@ Synchronously reads data from the stream.
**Example** **Example**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(path, "r+");
let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}); let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5});
``` ```
...@@ -2913,7 +2926,7 @@ Manages directories. Before calling a method of the **Dir** class, use the [open ...@@ -2913,7 +2926,7 @@ Manages directories. Before calling a method of the **Dir** class, use the [open
read(): Promise&lt;Dirent&gt; read(): Promise&lt;Dirent&gt;
Reads the next directory entry. This API uses a promise to return the result asynchronously. Reads the next directory entry. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2978,11 +2991,11 @@ Synchronously reads the next directory entry. ...@@ -2978,11 +2991,11 @@ Synchronously reads the next directory entry.
``` ```
### close ### close<sup>7+</sup>
close(): Promise&lt;void&gt; close(): Promise&lt;void&gt;
Closes a directory. This API uses a promise to return the result asynchronously. After a directory is closed, the file descriptor in Dir will be released and no directory entry can be read from Dir. Closes a directory. This API uses a promise to return the result. After a directory is closed, the file descriptor in Dir will be released and no directory entry can be read from Dir.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2995,7 +3008,7 @@ Closes a directory. This API uses a promise to return the result asynchronously. ...@@ -2995,7 +3008,7 @@ Closes a directory. This API uses a promise to return the result asynchronously.
``` ```
### close ### close<sup>7+</sup>
close(callback: AsyncCallback&lt;void&gt;): void close(callback: AsyncCallback&lt;void&gt;): void
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
>- The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. >- The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>- The APIs of this module are system APIs and cannot be called by third-party applications. Currently, these APIs can be called only by **filepicker**. >- The APIs of this module are system APIs and cannot be called by third-party applications. Currently, these APIs can be called only by **filepicker**.
This module provides service 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. Provides service 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.
## Modules to Import ## Modules to Import
...@@ -18,20 +18,20 @@ getRoot(options? : {dev? : DevInfo}) : Promise&lt;FileInfo[]&gt; ...@@ -18,20 +18,20 @@ getRoot(options? : {dev? : DevInfo}) : Promise&lt;FileInfo[]&gt;
Obtains information about the root album or directory in asynchronous mode. This API uses a promise to return the result. Obtains information about the root album or directory in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.| | options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
- Return value **Return value**
| Type| Description| | Type| Description|
| --- | -- | | --- | -- |
| Promise&lt;[FileInfo](#fileinfo)[]&gt; | Promise used to return the root album or directory information obtained.| | Promise&lt;[FileInfo](#fileinfo)[]&gt; | Promise used to return the root album or directory information obtained.|
- Example **Example**
```js ```js
filemanager.getRoot().then((fileInfo) => { filemanager.getRoot().then((fileInfo) => {
...@@ -51,24 +51,24 @@ getRoot(options? : {dev? : DevInfo}, callback : AsyncCallback&lt;FileInfo[]&gt;) ...@@ -51,24 +51,24 @@ getRoot(options? : {dev? : DevInfo}, callback : AsyncCallback&lt;FileInfo[]&gt;)
Obtains information about the root album or directory in asynchronous mode. This API uses a callback to return the result. Obtains information about the root album or directory in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.| | options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the root album or directory information obtained. | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the root album or directory information obtained. |
- Example **Example**
```js ```js
let option = { let options = {
"dev":{ "dev":{
name:"", "name":"local"
} }
}; };
filemanager.getRoot(option,(err, fileInfo)=>{ filemanager.getRoot(options, (err, fileInfo)=>{
if(Array.isArray(fileInfo)) { if(Array.isArray(fileInfo)) {
for (var i = 0; i < fileInfo.length; i++) { for (var i = 0; i < fileInfo.length; i++) {
console.log("file:"+JSON.stringify(fileInfo)); console.log("file:"+JSON.stringify(fileInfo));
...@@ -84,34 +84,35 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -84,34 +84,35 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
Obtains information about the second-level album or files in asynchronous mode. This API uses a promise to return the result. Obtains information about the second-level album or files in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| path | string | Yes| URI of the directory to query.| | path | string | Yes| URI of the directory to query.|
| type | string | Yes| Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.| | type | string | Yes| Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.| | options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.|
- Return value **Return value**
| Type| Description| | Type| Description|
| --- | -- | | --- | -- |
| Promise&lt;FileInfo[]&gt; | Promise used to return the album or file information obtained.| | Promise&lt;FileInfo[]&gt; | Promise used to return the album or file information obtained.|
- Error **Error**
| Error Info| Error Code|Description|
| -- | --- | -- |
| No such file or directory | 2 | The directory or album of the specified URI does not exist.|
| No such process | 3 | Failed to obtain the FMS service.|
| Not a directory | 20 | The object specified by the URI is not a directory or album.|
- Example | Error Info| Error Code|Description|
| -- | --- | -- |
| No such file or directory | 2 | The directory or album of the specified URI does not exist.|
| No such process | 3 | Failed to obtain the FMS service.|
| Not a directory | 20 | The object specified by the URI is not a directory or album.|
**Example**
```js ```js
// Obtain all files in the directory. // Obtain all files in the directory.
// Call listFile() and getRoot() to obtain the file URI. // Call listFile() and getRoot() to obtain the file URI.
let media_path = file.path let media_path = ""
filemanager.listFile(media_path, "file") filemanager.listFile(media_path, "file")
.then((fileInfo) => { .then((fileInfo) => {
if(Array.isArray(fileInfo)) { if(Array.isArray(fileInfo)) {
...@@ -120,42 +121,40 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -120,42 +121,40 @@ Obtains information about the second-level album or files in asynchronous mode.
} }
} }
}).catch((err) => { }).catch((err) => {
console.log("Failed to get file"+err);
console.log(err)
}); });
``` ```
## filemanager.listFile ## filemanager.listFile
listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : number, count? : number}, callback : AsyncCallback&lt;FileInfo[]&gt;) : void listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : number, count? : number}, callback : AsyncCallback&lt;FileInfo[]&gt;) : void
Obtains information about the second-level album or files in asynchronous mode. This API uses a callback to return the result. Obtains information about the second-level album or files in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
**Parameters**
- Parameters | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | URI of the directory to query. |
| type | string | Yes | Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the root album or directory information obtained. |
| Name | Type | Mandatory| Description | **Error**
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | URI of the directory to query. |
| type | string | Yes | Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. |
- Error
| Error Info | Error Code| Description | | Error Info | Error Code| Description |
| ------------------------- | ------ | ------------------------- | | ------------------------- | ------ | ------------------------- |
| No such file or directory | 2 | The directory or album of the specified URI does not exist.| | No such file or directory | 2 | The directory or album of the specified URI does not exist.|
| No such process | 3 | Failed to obtain the FMS service. | | No such process | 3 | Failed to obtain the FMS service. |
| Not a directory | 20 | The object specified by the URI is not a directory or album.| | Not a directory | 20 | The object specified by the URI is not a directory or album.|
- Example **Example**
```js ```js
// Call listFile() and getRoot() to obtain the file path. // Call listFile() and getRoot() to obtain the file path.
let fileInfos = await filemanager.getRoot(); let fileInfos = filemanager.getRoot();
let media_path = ""; let media_path = "";
for (let i = 0; i < fileInfos.length; i++) { for (let i = 0; i < fileInfos.length; i++) {
if (fileInfos[i].name == "image_album") { if (fileInfos[i].name == "image_album") {
...@@ -177,7 +176,7 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -177,7 +176,7 @@ Obtains information about the second-level album or files in asynchronous mode.
} }
} }
}).catch((err) => { }).catch((err) => {
console.log(err) console.log("Failed to get file"+err);
}); });
``` ```
...@@ -187,34 +186,35 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P ...@@ -187,34 +186,35 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
Creates a file in the specified path in asynchronous mode. This API uses a promise to return the result. Creates a file in the specified path in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| filename | string | Yes| Name of the file to create.|
| path | string | Yes| URI of the file to create.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
- Parameters **Return value**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| filename | string | Yes| Name of the file to create.|
| path | string | Yes| URI of the file to create.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
- Return value | Type| Description|
| --- | -- |
| Promise&lt;string&gt; | Promise used to return the URI of the file created.|
| Type| Description| **Error**
| --- | -- |
| promise<string>| Promise used to return the URI of the file created.|
- Error | Error Info| Error Code|Description|
| Error Info| Error Code|Description| | -- | --- | -- |
| -- | --- | -- | | Operation not permitted | 1 | A file with the same name already exists.|
| Operation not permitted | 1 | A file with the same name already exists.| | No such file or directory | 2 | The directory or album of the specified URI does not exist.|
| No such file or directory | 2 | The directory or album of the specified URI does not exist.| | No such process | 3 | Failed to obtain the FMS service.|
| No such process | 3 | Failed to obtain the FMS service.| | Not a directory | 20 | The object specified by the URI is not a directory or album.|
| Not a directory | 20 | The object specified by the URI is not a directory or album.|
- Example **Example**
```js ```js
// Create a file. // Create a file.
let media_path = file.uri // Obtain the file URI using listFile() and getRoot(). let media_path = "" // Obtain the file URI using listFile() and getRoot().
let name = "xxx.jpg" // File to be saved. let name = "xxx.jpg" // File to be saved.
filemanager.createFile(media_path, name).then((uri) => { filemanager.createFile(media_path, name).then((uri) => {
// The URI of the file created is returned. // The URI of the file created is returned.
...@@ -230,44 +230,50 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac ...@@ -230,44 +230,50 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
Creates a file in the specified path in asynchronous mode. This API uses a callback to return the result. Creates a file in the specified path in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| filename | string | Yes | Name of the file to create. | | filename | string | Yes | Name of the file to create. |
| path | string | Yes | URI of the file to create. | | path | string | Yes | URI of the file to create. |
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.| | options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the root album or directory information obtained. |
- Error **Error**
| Error Info | Error Code| Description | | Error Info | Error Code| Description |
| ------------------------- | ------ | ------------------------- | | ------------------------- | ------ | ------------------------- |
| Operation not permitted | 1 | A file with the same name already exists. | | Operation not permitted | 1 | A file with the same name already exists. |
| No such file or directory | 2 | The directory or album of the specified URI does not exist.| | No such file or directory | 2 | The directory or album of the specified URI does not exist.|
| No such process | 3 | Failed to obtain the FMS service. | | No such process | 3 | Failed to obtain the FMS service. |
| Not a directory | 20 | The object specified by the URI is not a directory or album.| | Not a directory | 20 | The object specified by the URI is not a directory or album.|
- Example **Example**
```js ```js
// Create a file. // Create a file.
// Call listFile() and getRoot() to obtain the file URI. // Call listFile() and getRoot() to obtain the file URI.
let media_path = file.path let media_path = ""
// File to be saved. // File to be saved.
let name = "xxx.jpg" let name = "xxx.jpg"
filemanager.createFile(media_path, name, (err, uri) => { let options = {
"dev":{
"name":"local"
}
};
filemanager.createFile(media_path, name, options, function(err, uri) {
// The URI of the file created is returned. // The URI of the file created is returned.
console.log("file uri:"+uri); console.log("file uri:"+uri);
}); });
``` ```
## FileInfo ## FileInfo
Defines the file information returned by **getRoot()** or **listFile()**. Defines the file information returned by **getRoot()** or **listFile()**.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
### Attributes ### Attributes
...@@ -284,7 +290,7 @@ Defines the file information returned by **getRoot()** or **listFile()**. ...@@ -284,7 +290,7 @@ Defines the file information returned by **getRoot()** or **listFile()**.
Defines the device type. Defines the device type.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
### Attributes ### Attributes
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册