diff --git a/zh-cn/application-dev/reference/apis/js-apis-document.md b/zh-cn/application-dev/reference/apis/js-apis-document.md
index 01d6e24a1c50a71f3e42bdf383315a6fc48e43d6..6cb8430b9697867344234c33467ad35bd2c135ec 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-document.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-document.md
@@ -12,7 +12,7 @@ import document from '@ohos.document';
## document.choose
-choose(type:string[]): Promise<string>
+choose(types:string[]): Promise<string>
通过文件管理器选择文件,异步返回文件URI,使用promise形式返回结果。
@@ -22,7 +22,7 @@ choose(type:string[]): Promise<string>
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------------------------- |
- | type | string[] | 否 | 限定文件选择的类型 |
+ | types | string[] | 否 | 限定文件选择的类型 |
- 返回值:
@@ -33,7 +33,8 @@ choose(type:string[]): Promise<string>
- 示例:
```js
- await document.choose(type);
+ let tpyes = [];
+ document.choose(types);
```
## document.choose
@@ -52,13 +53,14 @@ choose(callback:AsyncCallback<string>): void
- 示例:
```js
- await document.choose(function(err, uri) {
+ let uri = "";
+ document.choose(function(err, uri) {
//do something with uri
});
```
## document.choose
-choose(type:string[], callback:AsyncCallback<string>): void
+choose(types:string[], callback:AsyncCallback<string>): void
通过文件管理器选择文件,异步返回文件URI,使用callback形式返回结果。
@@ -68,20 +70,22 @@ choose(type:string[], callback:AsyncCallback<string>): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- |
- | type | string[] | 否 | 限定选择文件的类型 |
+ | types | string[] | 否 | 限定选择文件的类型 |
| callback | AsyncCallback<string> | 是 | 异步获取对应文件URI(注:当前返回错误码) |
- 示例:
```js
- await document.choose(type, function(err, uri) {
+ let types = [];
+ let uri = "";
+ document.choose(types, function(err, uri) {
//do something with uri
});
```
## document.show
-show(url:string, type:string):Promise<number>
+show(url:string, types:string):Promise<number>
异步打开URI对应的文件,使用promise形式返回结果。
@@ -92,7 +96,7 @@ show(url:string, type:string):Promise<number>
| 参数 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | ---------------------------- |
| uri | string | 是 | 待打开的文件URI |
- | type | string | 是 | 待打开文件的类型 |
+ | types | string | 是 | 待打开文件的类型 |
- 返回值:
@@ -103,12 +107,14 @@ show(url:string, type:string):Promise<number>
- 示例:
```js
- await document.show(uri, type);
+ let types = "";
+ let uri = "";
+ document.show(uri, types);
```
## document.show
-show(url:string, type:string, callback:AsyncCallback<void>): void
+show(url:string, types:string, callback:AsyncCallback<void>): void
异步打开URI对应的文件,使用callback形式返回结果。
@@ -119,13 +125,15 @@ show(url:string, type:string, callback:AsyncCallback<void>): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- |
| uri | string | 是 | 待打开的文件URI |
- | type | string | 是 | 待打开文件的类型 |
+ | types | string | 是 | 待打开文件的类型 |
| callback | AsyncCallback<void> | 是 | 异步打开uri对应文件(注:当前返回错误码) |
- 示例:
```js
- await document.show(uri, type, function(err) {
+ let types = "";
+ let uri = "";
+ document.show(uri, types, function(err) {
//do something
});
```
diff --git a/zh-cn/application-dev/reference/apis/js-apis-fileio.md b/zh-cn/application-dev/reference/apis/js-apis-fileio.md
index 122562e487b0cba7f55bf38ae2a5a2bae7ef6e5e..bc13f14d4338604b74040865e1e43c9b028abf46 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-fileio.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-fileio.md
@@ -18,10 +18,7 @@ import fileio from '@ohos.fileio';
```js
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
- let path = '';
- context.getFilesDir().then((data) => {
- path = data;
- })
+ let path = context.getFilesDir();
```
@@ -327,52 +324,11 @@ closeSync(fd: number): void
**示例:**
```js
+ let fd = fileio.openSync(path);
fileio.closeSync(fd);
```
-## fileio.close7+
-
-close(): Promise<void>
-
-关闭文件流,使用Promise异步回调。
-
-**系统能力**:SystemCapability.FileManagement.File.FileIO
-
-**返回值:**
- | 类型 | 说明 |
- | ------------------- | ---------------------------- |
- | Promise<void> | Promise对象。无返回值。 |
-
-**示例:**
- ```js
- fileio.close().then(function(){
- console.info("close file stream succeed");
- }).catch(function(err){
- console.info("close file stream failed with error:"+ err);
- });
- ```
-
-
-## fileio.close7+
-
-close(callback: AsyncCallback<void>): void
-
-关闭文件流,使用callback异步回调。
-
-**系统能力**:SystemCapability.FileManagement.File.FileIO
-
-**参数:**
- | 参数名 | 类型 | 必填 | 说明 |
- | -------- | ------------------------- | ---- | ------------- |
- | callback | AsyncCallback<void> | 是 | 异步关闭文件流之后的回调。 |
-
-**示例:**
- ```js
- fileio.close(function(err){
- // do something
- });
- ```
## fileio.copyFile
@@ -397,7 +353,8 @@ copyFile(src:string | number, dest:string | number, mode?:number):Promise<voi
**示例:**
```js
- fileio.copyFile(src, dest).then(function(){
+ let dest = "";
+ fileio.copyFile(path, dest).then(function(){
console.info("copyFile succeed");
}).catch(function(err){
console.info("copyFile failed with error:"+ err);
@@ -423,7 +380,8 @@ copyFile(src: string | number, dest: string | number, mode: number, callback: As
**示例:**
```js
- fileio.copyFile(src, dest, function (err) {
+ let dest = "";
+ fileio.copyFile(path, dest, function (err) {
// do something
});
```
@@ -446,7 +404,8 @@ copyFileSync(src: string | number, dest: string | number, mode?: number): void
**示例:**
```js
- fileio.copyFileSync(src, dest);
+ let dest = "";
+ fileio.copyFileSync(path, dest);
```
@@ -589,7 +548,7 @@ openSync(path:string, flags?:number, mode?:number): number
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | 是 | 待打开文件的应用沙箱路径。 |
| flags | number | 否 | 打开文件的选项,必须指定如下选项中的一个,默认以只读方式打开:
- 0o0:只读打开。
- 0o1:只写打开。
- 0o2:读写打开。
同时,也可给定如下选项,以按位或的方式追加,默认不给定任何额外选项:
- 0o100:若文件不存在,则创建文件。使用该选项时必须指定第三个参数 mode。
- 0o200:如果追加了0o100选项,且文件已经存在,则出错。
- 0o1000:如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。
- 0o2000:以追加方式打开,后续写将追加到文件末尾。
- 0o4000:如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续 IO 进行非阻塞操作。
- 0o200000:如果path不指向目录,则出错。
- 0o400000:如果path指向符号链接,则出错。
- 0o4010000:以同步IO的方式打开文件。 |
-| mode | number | 否 | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o666。
- 0o666:所有者具有读、写权限,所有用户组具有读、写权限,其余用户具有读、写权限。
- 0o640:所有者具有读、写权限,所有用户组具有读权限。
- 0o700:所有者具有读、写及可执行权限。
- 0o400:所有者具有读权限。
- 0o200:所有者具有写权限。
- 0o100:所有者具有可执行权限。
- 0o070:所有用户组具有读、写及可执行权限。
- 0o040:所有用户组具有读权限。
- 0o020:所有用户组具有写权限。
- 0o010:所有用户组具有可执行权限。
- 0o007:其余用户具有读、写及可执行权限。
- 0o004:其余用户具有读权限。
- 0o002:其余用户具有写权限。
- 0o001:其余用户具有可执行权限。
创建出的文件权限受umask影响,umask随进程启动确定,其修改当前不开放。 |
+| mode | number | 否 | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o666。
- 0o666:所有者具有读、写权限,所有用户组具有读、写权限,其余用户具有读、写权限。
- 0o700:所有者具有读、写及可执行权限。
- 0o400:所有者具有读权限。
- 0o200:所有者具有写权限。
- 0o100:所有者具有可执行权限。
- 0o070:所有用户组具有读、写及可执行权限。
- 0o040:所有用户组具有读权限。
- 0o020:所有用户组具有写权限。
- 0o010:所有用户组具有可执行权限。
- 0o007:其余用户具有读、写及可执行权限。
- 0o004:其余用户具有读权限。
- 0o002:其余用户具有写权限。
- 0o001:其余用户具有可执行权限。
创建出的文件权限受umask影响,umask随进程启动确定,其修改当前不开放。 |
**返回值:**
| 类型 | 说明 |
@@ -598,15 +557,7 @@ openSync(path:string, flags?:number, mode?:number): number
**示例:**
```js
- let fd = fileio.openSync(path, 0o102, 0o640);
- ```
- ```js
- let fd = fileio.openSync(path, 0o102, 0o666);
- fileio.writeSync(fd, 'hello world');
- let fd1 = fileio.openSync(path, 0o2002);
- fileio.writeSync(fd1, 'hello world');
- let num = fileio.readSync(fd1, new ArrayBuffer(4096), {position: 0});
- console.info("num == " + num);
+ let fd = fileio.openSync(path);
```
@@ -879,7 +830,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
**示例:**
```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){
console.info("write data to file succeed and size is:"+ number);
}).catch(function(err){
@@ -976,7 +927,7 @@ hash(path: string, algorithm: string): Promise<string>
fileio.hash(path, "sha256").then(function(str){
console.info("calculate file hash succeed:"+ str);
}).catch(function(error){
- console.info("calculate file hash failed with error:"+ err);
+ console.info("calculate file hash failed with error:"+ error);
});
```
@@ -998,7 +949,7 @@ hash(path: string, algorithm: string, callback: AsyncCallback<string>): vo
**示例:**
```js
- fileio.hash(fpath, "sha256", function(err, hashStr) {
+ fileio.hash(path, "sha256", function(err, hashStr) {
if (hashStr) {
console.info("calculate file hash succeed:"+ hashStr);
}
@@ -1027,7 +978,7 @@ chmod(path: string, mode: number):Promise<void>
**示例:**
```js
- fileio.chmod(path, mode).then(function() {
+ fileio.chmod(path, 0o400).then(function() {
console.info("chmod succeed");
}).catch(function(err){
console.info("chmod failed with error:"+ err);
@@ -1052,7 +1003,7 @@ chmod(path: string, mode: number, callback: AsyncCallback<void>): void
**示例:**
```js
- fileio.chmod(path, mode, function (err) {
+ fileio.chmod(path, 0o400, function (err) {
// do something
});
```
@@ -1074,7 +1025,7 @@ chmodSync(path: string, mode: number): void
**示例:**
```js
- fileio.chmodSync(fpath, mode);
+ fileio.chmodSync(path, 0o400);
```
@@ -1098,6 +1049,7 @@ fstat(fd: number): Promise<Stat>
**示例:**
```js
+ let fd = fileio.openSync(path);
fileio.fstat(fd).then(function(stat){
console.info("fstat succeed:"+ JSON.stringify(stat));
}).catch(function(err){
@@ -1201,6 +1153,8 @@ ftruncate(fd: number, len: number, callback:AsyncCallback<void>): void
**示例:**
```js
+ let fd = fileio.openSync(path);
+ let len = 5;
fileio.ftruncate(fd, len, function(err){
// do something
});
@@ -1223,6 +1177,8 @@ ftruncateSync(fd: number, len?: number): void
**示例:**
```js
+ let fd = fileio.openSync(path);
+ let len = 5;
fileio.ftruncateSync(fd, len);
```
@@ -1248,6 +1204,7 @@ truncate(path: string, len?: number): Promise<void>
**示例:**
```js
+ let len = 5;
fileio.truncate(path, len).then(function(){
console.info("truncate file succeed");
}).catch(function(err){
@@ -1273,6 +1230,7 @@ truncate(path: string, len: number, callback:AsyncCallback<void>): void
**示例:**
```js
+ let len = 5;
fileio.truncate(path, len, function(err){
// do something
});
@@ -1295,6 +1253,7 @@ truncateSync(path: string, len?: number): void
**示例:**
```js
+ let len = 5;
fileio.truncateSync(path, len);
```
@@ -1353,7 +1312,7 @@ readText(filePath: string, options: {
**示例:**
```js
- fileio.readText(path, function(err, str){
+ fileio.readText(path, { position: pos, length: len, encoding: 'UTF-8' }, function (err, str){
// do something
});
```
@@ -1409,7 +1368,7 @@ lstat(path: string): Promise<Stat>
**示例:**
```js
fileio.lstat(path).then(function(stat){
- console.info("get link status succeed:"+ number);
+ console.info("get link status succeed:"+ stat.rdev);
}).catch(function(err){
console.info("get link status failed with error:"+ err);
});
@@ -1462,69 +1421,6 @@ lstatSync(path:string): Stat
```
-## fileio.read7+
-
-read(buffer: ArrayBuffer, options?: {
- position?: number;
- offset?: number;
- length?: number;
-}): Promise<ReadOut>
-
-从文件读取数据,使用Promise异步回调。
-
-**系统能力**:SystemCapability.FileManagement.File.FileIO
-
-**参数:**
- | 参数名 | 类型 | 必填 | 说明 |
- | ------- | ----------- | ---- | ------------------------------------------------------------ |
- | buffer | ArrayBuffer | 是 | 用于保存读取到的文件数据的缓冲区。 |
- | options | Object | 否 | 支持如下选项:
- offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。
约束:offset+length<=buffer.size。 |
-
-**返回值:**
- | 类型 | 说明 |
- | ---------------------------------- | ------ |
- | Promise<[ReadOut](#readout)> | Promise对象。返回读取的结果。 |
-
-**示例:**
- ```js
- fileio.read(new ArrayBuffer(4096)).then(function(readout){
- console.info("read file data succeed");
- console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
- }).catch(function(err){
- console.info("read file data failed with error:"+ err);
- });
- ```
-
-
-## fileio.read7+
-
-read(buffer: ArrayBuffer, options: {
- position?: number;
- offset?: number;
- length?: number;
-}, callback: AsyncCallback<ReadOut>): void
-
-从文件读取数据,使用callback异步回调。
-
-**系统能力**:SystemCapability.FileManagement.File.FileIO
-
-**参数:**
- | 参数名 | 类型 | 必填 | 说明 |
- | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
- | buffer | ArrayBuffer | 是 | 用于保存读取到的文件数据的缓冲区。 |
- | options | Object | 否 | 支持如下选项:
- offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。
约束:offset+length<=buffer.size。 |
- | callback | AsyncCallback<[ReadOut](#readout)> | 是 | 异步从文件读取数据之后的回调。 |
-
-**示例:**
- ```js
- let buf = new ArrayBuffer(4096);
- fileio.read(buf, function (err, readOut) {
- if (readOut) {
- console.info("read file data succeed");
- console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
- }
- });
- ```
## fileio.rename7+
@@ -1548,7 +1444,8 @@ rename(oldPath: string, newPath: string): Promise<void>
**示例:**
```js
- fileio.rename(oldPath, newPath).then(function() {
+ let newPath = path +"123";
+ fileio.rename(path, newPath).then(function() {
console.info("rename succeed");
}).catch(function(err){
console.info("rename failed with error:"+ err);
@@ -1573,7 +1470,8 @@ rename(oldPath: string, newPath: string, callback: AsyncCallback<void>): v
**示例:**
```js
- fileio.rename(oldPath, newPath, function(err){
+ let newPath = path +"123";
+ fileio.rename(path, newPath, function(err){
});
```
@@ -1594,7 +1492,8 @@ renameSync(oldPath: string, newPath: string): void
**示例:**
```js
- fileio.renameSync(oldPath, newPath);
+ let newPath = path +"123";
+ fileio.renameSync(path, newPath);
```
@@ -1618,6 +1517,7 @@ fsync(fd: number): Promise<void>
**示例:**
```js
+ let fd = fileio.openSync(path);
fileio.fsync(fd).then(function(){
console.info("sync data succeed");
}).catch(function(err){
@@ -1641,7 +1541,8 @@ fsync(fd: number, callback: AsyncCallback<void>): void
| Callback | AsyncCallback<void> | 是 | 异步将文件数据同步之后的回调。 |
**示例:**
- ```js
+ ```js
+ let fd = fileio.openSync(path);
fileio.fsync(fd, function(err){
// do something
});
@@ -1663,6 +1564,7 @@ fsyncSync(fd: number): void
**示例:**
```js
+ let fd = fileio.openSync(path);
fileio.fyncsSync(fd);
```
@@ -1686,7 +1588,8 @@ fdatasync(fd: number): Promise<void>
| Promise<void> | Promise对象。无返回值。 |
**示例:**
- ```js
+ ```js
+ let fd = fileio.openSync(path);
fileio.fdatasync(fd).then(function(err) {
console.info("sync data succeed");
}).catch(function(err){
@@ -1711,6 +1614,7 @@ fdatasync(fd: number, callback:AsyncCallback<void>): void
**示例:**
```js
+ let fd = fileio.openSync(path);
fileio.fdatasync (fd, function (err) {
// do something
});
@@ -1732,6 +1636,7 @@ fdatasyncSync(fd: number): void
**示例:**
```js
+ let fd = fileio.openSync(path);
let stat = fileio.fdatasyncSync(fd);
```
@@ -1757,7 +1662,8 @@ symlink(target: string, srcPath: string): Promise<void>
**示例:**
```js
- fileio.symlink(target, srcPath).then(function() {
+ let srcPath = "";
+ fileio.symlink(path, srcPath).then(function() {
console.info("symlink succeed");
}).catch(function(err){
console.info("symlink failed with error:"+ err);
@@ -1782,7 +1688,8 @@ symlink(target: string, srcPath: string, callback: AsyncCallback<void>): v
**示例:**
```js
- fileio.symlink(target, srcPath, function (err) {
+ let srcPath = "";
+ fileio.symlink(path, srcPath, function (err) {
// do something
});
```
@@ -1804,7 +1711,8 @@ symlinkSync(target: string, srcPath: string): void
**示例:**
```js
- fileio.symlinkSync(target, srcPath);
+ let srcPath = "";
+ fileio.symlinkSync(path, srcPath);
```
@@ -1857,7 +1765,7 @@ chown(path: string, uid: number, gid: number, callback: AsyncCallback<void>
**示例:**
```js
- let stat = fileio.statSync(fpath)
+ let stat = fileio.statSync(path)
fileio.chown(path, stat.uid, stat.gid, function (err){
// do something
});
@@ -1881,7 +1789,7 @@ chownSync(path: string, uid: number, gid: number): void
**示例:**
```js
- let stat = fileio.statSync(fpath)
+ let stat = fileio.statSync(path)
fileio.chownSync(path, stat.uid, stat.gid);
```
@@ -1981,6 +1889,8 @@ fchmod(fd: number, mode: number): Promise<void>
**示例:**
```js
+ let fd = fileio.openSync(path);
+ let mode = 0o400;
fileio.fchmod(fd, mode).then(function() {
console.info("chmod succeed");
}).catch(function(err){
@@ -2006,6 +1916,8 @@ fchmod(fd: number, mode: number, callback: AsyncCallback<void>): void
**示例:**
```js
+ let fd = fileio.openSync(path);
+ let mode = 0o400;
fileio.fchmod(fd, mode, function (err) {
// do something
});
@@ -2028,7 +1940,9 @@ fchmodSync(fd: number, mode: number): void
**示例:**
```js
- fileio.fchmodSync(fd, mode);
+ let fd = fileio.openSync(path);
+ let mode = 0o400;
+ fileio.fchmodSync(fd, mode);
```
@@ -2078,6 +1992,7 @@ createStream(path: string, mode: string, callback: AsyncCallback<Stream>):
**示例:**
```js
+ let mode = 0o400;
fileio.createStream(path, mode, function(err, stream){
// do something
});
@@ -2130,6 +2045,8 @@ fdopenStream(fd: number, mode: string): Promise<Stream>
**示例:**
```js
+ let fd = fileio.openSync(path);
+ let mode = 0o400;
fileio.fdopenStream(fd, mode).then(function(stream){
console.info("openStream succeed");
}).catch(function(err){
@@ -2155,6 +2072,8 @@ fdopenStream(fd: number, mode: string, callback: AsyncCallback<Stream>): v
**示例:**
```js
+ let fd = fileio.openSync(path);
+ let mode = 0o400;
fileio.fdopenStream(fd, mode, function (err, stream) {
// do something
});
@@ -2182,6 +2101,7 @@ fdopenStreamSync(fd: number, mode: string): Stream
**示例:**
```js
+ let fd = fileio.openSync(path);
let ss = fileio.fdopenStreamSync(fd, "r+");
```
@@ -2208,6 +2128,7 @@ fchown(fd: number, uid: number, gid: number): Promise<void>
**示例:**
```js
+ let fd = fileio.openSync(path);
let stat = fileio.statSync(path);
fileio.fchown(fd, stat.uid, stat.gid).then(function() {
console.info("chown succeed");
@@ -2235,7 +2156,8 @@ fchown(fd: number, uid: number, gid: number, callback: AsyncCallback<void>
**示例:**
```js
- let stat = fileio.statSync(fpath);
+ let fd = fileio.openSync(path);
+ let stat = fileio.statSync(path);
fileio.fchown(fd, stat.uid, stat.gid, function (err){
// do something
});
@@ -2259,7 +2181,8 @@ fchownSync(fd: number, uid: number, gid: number): void
**示例:**
```js
- let stat = fileio.statSync(fpath);
+ let fd = fileio.openSync(path);
+ let stat = fileio.statSync(path);
fileio.fchownSync(fd, stat.uid, stat.gid);
```
@@ -2364,6 +2287,8 @@ createWatcher(filename: string, events: number, callback: AsyncCallback<numbe
**示例:**
```js
+ let filename = path +"/test.txt";
+ let events = 1;
fileio.createWatcher(filename, events, function(watcher){
// do something
});
@@ -2498,7 +2423,7 @@ isFile(): boolean
**示例:**
```js
- let isFile = fileio.statSync(fpath).isFile();
+ let isFile = fileio.statSync(path).isFile();
```
@@ -2600,7 +2525,7 @@ close(): Promise<void>
**示例:**
```js
- let ss= fileio.createStreamSync(path);
+ let ss= fileio.createStreamSync(path,"r+");
ss.close().then(function(){
console.info("close fileStream succeed");
}).catch(function(err){
@@ -2641,7 +2566,7 @@ closeSync(): void
**示例:**
```js
- let ss= fileio.createStreamSync(path);
+ let ss= fileio.createStreamSync(path,"r+");
ss.closeSync();
```
@@ -2661,7 +2586,7 @@ flush(): Promise<void>
**示例:**
```js
- let ss= fileio.createStreamSync(path);
+ let ss= fileio.createStreamSync(path,"r+");
ss.flush().then(function (){
console.info("flush succeed");
}).catch(function(err){
@@ -2685,7 +2610,7 @@ flush(callback: AsyncCallback<void>): void
**示例:**
```js
- let ss= fileio.createStreamSync(path);
+ let ss= fileio.createStreamSync(path,"r+");
ss.flush(function (err) {
// do something
});
@@ -2702,7 +2627,7 @@ flushSync(): void
**示例:**
```js
- let ss= fileio.createStreamSync(path);
+ let ss= fileio.createStreamSync(path,"r+");
ss.flushSync();
```
@@ -2733,7 +2658,7 @@ write(buffer: ArrayBuffer | string, options?: {
**示例:**
```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){
console.info("write succeed and size is:"+ number);
}).catch(function(err){
@@ -2764,7 +2689,7 @@ write(buffer: ArrayBuffer | string, options: {
**示例:**
```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) {
if (bytesWritten) {
// do something
@@ -2800,7 +2725,7 @@ writeSync(buffer: ArrayBuffer | string, options?: {
**示例:**
```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'});
```
@@ -2830,10 +2755,10 @@ read(buffer: ArrayBuffer, options?: {
**示例:**
```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){
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){
console.info("read data failed with error:"+ err);
});
@@ -2861,7 +2786,7 @@ read(buffer: ArrayBuffer, options: {
**示例:**
```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) {
if (readOut) {
console.info("read data succeed");
@@ -2898,7 +2823,7 @@ readSync(buffer: ArrayBuffer, options?: {
**示例:**
```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});
```
@@ -2923,7 +2848,7 @@ read(): Promise<Dirent>
**示例:**
```js
- let dir = fileio.opendirSync(path);
+ dir = fileio.opendirSync(path);
dir.read().then(function (dirent){
console.log("read succeed:"+JSON.stringify(dirent));
}).catch(function(err){
@@ -2947,7 +2872,7 @@ read(callback: AsyncCallback<Dirent>): void
**示例:**
```js
- let dir = fileio.opendirSync(path);
+ dir = fileio.opendirSync(path);
dir.read(function (err, dirent) {
if (dirent) {
// do something
@@ -2972,45 +2897,11 @@ readSync(): Dirent
**示例:**
```js
- let dir = fileio.opendirSync(path);
+ dir = fileio.opendirSync(path);
let dirent = dir.readSync();
```
-### close
-
-close(): Promise<void>
-
-异步关闭目录,使用promise形式返回结果。目录被关闭后,Dir中持有的文件描述将被释放,后续将无法从Dir中读取目录项。
-
-**系统能力**:SystemCapability.FileManagement.File.FileIO
-
-**示例:**
- ```js
- let dir = fileio.opendirSync(path);
- dir.close().then(function(err){
- console.info("close dir successfully");
- });
- ```
-
-
- ### close
-
-close(callback: AsyncCallback<void>): void
-
-异步关闭目录,使用callback形式返回结果。目录被关闭后,Dir中持有的文件描述将被释放,后续将无法从Dir中读取目录项。
-
-**系统能力**:SystemCapability.FileManagement.File.FileIO
-
-**示例:**
- ```js
- let dir = fileio.opendirSync(path);
- dir.close(function(err){
- console.info("close dir successfully");
- });
- ```
-
-
### closeSync
closeSync(): void
@@ -3021,7 +2912,7 @@ closeSync(): void
**示例:**
```js
- let dir = fileio.opendirSync(path);
+ dir = fileio.opendirSync(path);
dir.closeSync();
```
@@ -3054,7 +2945,7 @@ isBlockDevice(): boolean
**示例:**
```js
- let dir = fileio.opendirSync(path);
+ dir = fileio.opendirSync(path);
let isBLockDevice = dir.readSync().isBlockDevice();
```
@@ -3074,7 +2965,7 @@ isCharacterDevice(): boolean
**示例:**
```js
- let dir = fileio.opendirSync(path);
+ dir = fileio.opendirSync(path);
let isCharacterDevice = dir.readSync().isCharacterDevice();
```
@@ -3094,7 +2985,7 @@ isDirectory(): boolean
**示例:**
```js
- let dir = fileio.opendirSync(path);
+ dir = fileio.opendirSync(path);
let isDirectory = dir.readSync().isDirectory();
```
@@ -3114,7 +3005,7 @@ isFIFO(): boolean
**示例:**
```js
- let dir = fileio.opendirSync(path);
+ dir = fileio.opendirSync(path);
let isFIFO = dir.readSync().isFIFO();
```
@@ -3134,7 +3025,7 @@ isFile(): boolean
**示例:**
```js
- let dir = fileio.opendirSync(path);
+ dir = fileio.opendirSync(path);
let isFile = dir.readSync().isFile();
```
@@ -3154,7 +3045,7 @@ isSocket(): boolean
**示例:**
```js
- let dir = fileio.opendirSync(dpath);
+ dir = fileio.opendirSync(path);
let isSocket = dir.readSync().isSocket();
```
@@ -3174,6 +3065,6 @@ isSymbolicLink(): boolean
**示例:**
```js
- let dir = fileio.opendirSync(path);
+ dir = fileio.opendirSync(path);
let isSymbolicLink = dir.readSync().isSymbolicLink();
```
diff --git a/zh-cn/application-dev/reference/apis/js-apis-filemanager.md b/zh-cn/application-dev/reference/apis/js-apis-filemanager.md
index d2a521a9d6965e374b4dfd3e1222214ad3c9786e..baf1e22240d033d0df379111f9f020a338df5e89 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-filemanager.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-filemanager.md
@@ -111,7 +111,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
```js
// 获取目录下所有文件
// 通过listFile、getRoot获取的文件uri
- let media_path = file.path
+ let media_path = ""
filemanager.listFile(media_path, "file")
.then((fileInfo) => {
if(Array.isArray(fileInfo)) {
@@ -120,6 +120,9 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
}
}
}).catch((err) => {
+
+
+
console.log(err)
});
```
@@ -152,7 +155,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
```js
// 通过listFile、getRoot获取的文件path
- let fileInfos = await filemanager.getRoot();
+ let fileInfos = filemanager.getRoot();
let media_path = "";
for (let i = 0; i < fileInfos.length; i++) {
if (fileInfos[i].name == "image_album") {
@@ -197,7 +200,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
| 类型 | 说明 |
| --- | -- |
- | Promise<string> | 文件uri |
+ | string | 文件uri |
- 异常
| 错误名称 | 错误类型 | 错误码 |说明 |
@@ -211,7 +214,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
```js
// 创建文件,返回文件uri
- let media_path = file.uri // 通过listFile、getRoot获取的文件uri
+ let media_path = "" // 通过listFile、getRoot获取的文件uri
let name = "xxx.jpg" // 待保存文件的后缀
filemanager.createFile(media_path, name).then((uri) => {
// 返回uri给应用
@@ -252,13 +255,15 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
```js
// 创建文件,返回文件uri
// 通过listFile、getRoot获取的文件uri
- let media_path = file.path
+ let media_path = ""
// 待保存文件的后缀
let name = "xxx.jpg"
- filemanager.createFile(media_path, name, (err, uri) => {
+ let dev = "";
+ filemanager.createFile(media_path, name, { DevInfo: dev }, function(err, uri) {
// 返回uri给应用
- console.log("file uri:"+uri);
- });
+ console.log("file uri:"+uri);
+ });
+
```
## FileInfo
diff --git a/zh-cn/application-dev/reference/apis/js-apis-securityLabel.md b/zh-cn/application-dev/reference/apis/js-apis-securityLabel.md
index 9c5df1940acdca9c8c68801b3539d924ee473c48..9a912a0efdb0691018bb535dcf4f310da5dafbb3 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-securityLabel.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-securityLabel.md
@@ -13,20 +13,12 @@ import securityLabel from '@ohos.securityLabel';
## 使用说明
-使用该功能模块对文件/目录进行操作前,需要先获取其应用沙箱路径,获取方式及其接口用法请参考:[Context模块的接口getOrCreateLocalDir](js-apis-Context.md)。
-
-“文件/目录应用沙箱路径”=“应用目录路径”+“文件/目录名”
-
-通过上述接口获取到应用目录路径dir,文件名为“xxx.txt”,文件所在应用沙箱路径为:
-
-```js
-let path = dir + "/xxx.txt";
-```
-
-文件描述符fd:
+使用该功能模块对文件/目录进行操作前,需要先获取其应用沙箱路径,获取方式及其接口用法请参考:
```js
-let fd = fileio.openSync(path, 0o102, 0o666);
+import featureAbility from '@ohos.ability.featureAbility';
+let context = featureAbility.getContext();
+let path = context.getFilesDir();
```
## securityLabel.setSecurityLabel
@@ -53,6 +45,7 @@ setSecurityLabel(path:string, dataLevel:string):Promise<void>
**示例:**
```js
+ let dataLevel = "s4";
securityLabel.setSecurityLabel(path, dataLevel).then(function(){
console.info("setSecurityLabel successfully");
}).catch(function(error){
@@ -79,6 +72,7 @@ setSecurityLabel(path:string, dataLevel:string, callback: AsyncCallback<void&
**示例:**
```js
+ let dataLevel = "s4";
securityLabel.setSecurityLabel(path, dataLevel, function(error){
console.info("setSecurityLabel:" + JSON.stringify(error));
});
@@ -101,6 +95,7 @@ setSecurityLabelSync(path:string, dataLevel:string):void
**示例:**
```js
+let dataLevel = "s4";
securityLabel.setSecurityLabelSync(path, dataLevel);
```
@@ -127,6 +122,7 @@ getSecurityLabel(path:string):Promise<string>
**示例:**
```js
+ let dataLevel = "s4";
securityLabel.getSecurityLabel(path).then(function(dataLevel){
console.log("getSecurityLabel successfully:" + dataLevel);
}).catch(function(error){
@@ -152,7 +148,8 @@ getSecurityLabel(path:string, callback:AsyncCallback<string>): void
**示例:**
```js
- securityLabel.getSecurityLabel(function(error, dataLevel){
+ let dataLevel = "s4";
+ securityLabel.getSecurityLabel(path,function(error, dataLevel){
console.log("getSecurityLabel successfully:" + dataLevel);
});
```
diff --git a/zh-cn/application-dev/reference/apis/js-apis-storage-statistics.md b/zh-cn/application-dev/reference/apis/js-apis-storage-statistics.md
index 3934392f9ea9ecd2181221d819d24c8689bac3ac..f9d9047f6f9c85483e40cc7efe78b749eefc3fea 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-storage-statistics.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-storage-statistics.md
@@ -10,7 +10,7 @@
## 导入模块
```js
-import storagestatistics from "@ohos.storageStatistics";
+import storageStatistics from "@ohos.storageStatistics";
```
## storagestatistics.getTotalSizeOfVolume
@@ -227,7 +227,7 @@ getCurrentBundleStats(): Promise
- 示例
```js
- let bundleStats = await storageStatistics.getCurrentBundleStats();
+ let bundleStats = storageStatistics.getCurrentBundleStats();
console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
```
@@ -292,7 +292,7 @@ getTotalSize(): Promise
- 示例
```js
- let number = await storageStatistics.getTotalSize();
+ let number = storageStatistics.getTotalSize();
console.info("getTotalSize successfully:"+ JSON.stringify(number));
```
@@ -345,7 +345,7 @@ getFreeSize(): Promise
- 示例
```js
- let number = await storageStatistics.getFreeSize();
+ let number = storageStatistics.getFreeSize();
console.info("getFreeSize successfully:"+ JSON.stringify(number));
```
@@ -493,6 +493,7 @@ getUserStorageStats(userId?: string, callback:AsyncCallback<StorageStats>)
- 示例
```js
+ let userId = "";
storagestatistics.getUserStorageStats(userId, function(error, StorageStats){
// do something
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));