未验证 提交 f398ffcb 编写于 作者: O openharmony_ci 提交者: Gitee

!6119 文档修改

Merge pull request !6119 from wangbo/master
......@@ -16,7 +16,7 @@ choose(types:string[]): Promise<string>
通过文件管理器选择文件,异步返回文件URI,使用promise形式返回结果。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**系统能力**:SystemCapability.FileManagement.UserFileService
- 参数:
......@@ -42,7 +42,7 @@ choose(callback:AsyncCallback<string>): void
通过文件管理器选择文件,异步返回文件URI,使用callback形式返回结果。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**系统能力**:SystemCapability.FileManagement.UserFileService
- 参数:
......@@ -64,7 +64,7 @@ choose(types:string[], callback:AsyncCallback<string>): void
通过文件管理器选择文件,异步返回文件URI,使用callback形式返回结果。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**系统能力**:SystemCapability.FileManagement.UserFileService
- 参数:
......@@ -85,11 +85,11 @@ choose(types:string[], callback:AsyncCallback<string>): void
## document.show
show(url:string, types:string):Promise<number>
show(uri:string, types:string):Promise<void>
异步打开URI对应的文件,使用promise形式返回结果。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**系统能力**:SystemCapability.FileManagement.UserFileService
- 参数:
......@@ -114,11 +114,11 @@ show(url:string, types:string):Promise<number>
## document.show
show(url:string, types:string, callback:AsyncCallback<void>): void
show(uri:string, types:string, callback:AsyncCallback<void>): void
异步打开URI对应的文件,使用callback形式返回结果。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**系统能力**:SystemCapability.FileManagement.UserFileService
- 参数:
......
......@@ -18,7 +18,10 @@ import fileio from '@ohos.fileio';
```js
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
let path = context.getFilesDir();
let path = '';
context.getFilesDir().then((data) => {
path = data;
})
```
......@@ -324,11 +327,52 @@ closeSync(fd: number): void
**示例:**
```js
let fd = fileio.openSync(path);
fileio.closeSync(fd);
```
## fileio.close<sup>7+</sup>
close(): Promise&lt;void&gt;
关闭文件流,使用Promise异步回调。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**返回值:**
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | 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.close<sup>7+</sup>
close(callback: AsyncCallback&lt;void&gt;): void
关闭文件流,使用callback异步回调。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步关闭文件流之后的回调。 |
**示例:**
```js
fileio.close(function(err){
// do something
});
```
## fileio.copyFile
......@@ -353,8 +397,7 @@ copyFile(src:string | number, dest:string | number, mode?:number):Promise&lt;voi
**示例:**
```js
let dest = "";
fileio.copyFile(path, dest).then(function(){
fileio.copyFile(src, dest).then(function(){
console.info("copyFile succeed");
}).catch(function(err){
console.info("copyFile failed with error:"+ err);
......@@ -380,8 +423,7 @@ copyFile(src: string | number, dest: string | number, mode: number, callback: As
**示例:**
```js
let dest = "";
fileio.copyFile(path, dest, function (err) {
fileio.copyFile(src, dest, function (err) {
// do something
});
```
......@@ -404,8 +446,7 @@ copyFileSync(src: string | number, dest: string | number, mode?: number): void
**示例:**
```js
let dest = "";
fileio.copyFileSync(path, dest);
fileio.copyFileSync(src, dest);
```
......@@ -548,7 +589,7 @@ openSync(path:string, flags?:number, mode?:number): number
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | 是 | 待打开文件的应用沙箱路径。 |
| flags | number | 否 | 打开文件的选项,必须指定如下选项中的一个,默认以只读方式打开:<br/>-&nbsp;0o0:只读打开。<br/>-&nbsp;0o1:只写打开。<br/>-&nbsp;0o2:读写打开。<br/>同时,也可给定如下选项,以按位或的方式追加,默认不给定任何额外选项:<br/>-&nbsp;0o100:若文件不存在,则创建文件。使用该选项时必须指定第三个参数&nbsp;mode。<br/>-&nbsp;0o200:如果追加了0o100选项,且文件已经存在,则出错。<br/>-&nbsp;0o1000:如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。<br/>-&nbsp;0o2000:以追加方式打开,后续写将追加到文件末尾。<br/>-&nbsp;0o4000:如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续&nbsp;IO&nbsp;进行非阻塞操作。<br/>-&nbsp;0o200000:如果path不指向目录,则出错。<br/>-&nbsp;0o400000:如果path指向符号链接,则出错。<br/>-&nbsp;0o4010000:以同步IO的方式打开文件。 |
| mode | number | 否 | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o666。<br/>-&nbsp;0o666:所有者具有读、写权限,所有用户组具有读、写权限,其余用户具有读、写权限。<br/>-&nbsp;0o700:所有者具有读、写及可执行权限。<br/>-&nbsp;0o400:所有者具有读权限。<br/>-&nbsp;0o200:所有者具有写权限。<br/>-&nbsp;0o100:所有者具有可执行权限。<br/>-&nbsp;0o070:所有用户组具有读、写及可执行权限。<br/>-&nbsp;0o040:所有用户组具有读权限。<br/>-&nbsp;0o020:所有用户组具有写权限。<br/>-&nbsp;0o010:所有用户组具有可执行权限。<br/>-&nbsp;0o007:其余用户具有读、写及可执行权限。<br/>-&nbsp;0o004:其余用户具有读权限。<br/>-&nbsp;0o002:其余用户具有写权限。<br/>-&nbsp;0o001:其余用户具有可执行权限。<br/>创建出的文件权限受umask影响,umask随进程启动确定,其修改当前不开放。 |
| mode | number | 否 | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o666。<br/>-&nbsp;0o666:所有者具有读、写权限,所有用户组具有读、写权限,其余用户具有读、写权限。<br/>-&nbsp;0o640:所有者具有读、写权限,所有用户组具有读权限。<br/>-&nbsp;0o700:所有者具有读、写及可执行权限。<br/>-&nbsp;0o400:所有者具有读权限。<br/>-&nbsp;0o200:所有者具有写权限。<br/>-&nbsp;0o100:所有者具有可执行权限。<br/>-&nbsp;0o070:所有用户组具有读、写及可执行权限。<br/>-&nbsp;0o040:所有用户组具有读权限。<br/>-&nbsp;0o020:所有用户组具有写权限。<br/>-&nbsp;0o010:所有用户组具有可执行权限。<br/>-&nbsp;0o007:其余用户具有读、写及可执行权限。<br/>-&nbsp;0o004:其余用户具有读权限。<br/>-&nbsp;0o002:其余用户具有写权限。<br/>-&nbsp;0o001:其余用户具有可执行权限。<br/>创建出的文件权限受umask影响,umask随进程启动确定,其修改当前不开放。 |
**返回值:**
| 类型 | 说明 |
......@@ -557,7 +598,15 @@ openSync(path:string, flags?:number, mode?:number): number
**示例:**
```js
let fd = fileio.openSync(path);
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);
```
......@@ -830,7 +879,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
**示例:**
```js
let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
let fd = fileio.openSync(fpath, 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){
......@@ -927,7 +976,7 @@ hash(path: string, algorithm: string): Promise&lt;string&gt;
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:"+ error);
console.info("calculate file hash failed with error:"+ err);
});
```
......@@ -949,7 +998,7 @@ hash(path: string, algorithm: string, callback: AsyncCallback&lt;string&gt;): vo
**示例:**
```js
fileio.hash(path, "sha256", function(err, hashStr) {
fileio.hash(fpath, "sha256", function(err, hashStr) {
if (hashStr) {
console.info("calculate file hash succeed:"+ hashStr);
}
......@@ -978,7 +1027,7 @@ chmod(path: string, mode: number):Promise&lt;void&gt;
**示例:**
```js
fileio.chmod(path, 0o400).then(function() {
fileio.chmod(path, mode).then(function() {
console.info("chmod succeed");
}).catch(function(err){
console.info("chmod failed with error:"+ err);
......@@ -1003,7 +1052,7 @@ chmod(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
fileio.chmod(path, 0o400, function (err) {
fileio.chmod(path, mode, function (err) {
// do something
});
```
......@@ -1025,7 +1074,7 @@ chmodSync(path: string, mode: number): void
**示例:**
```js
fileio.chmodSync(path, 0o400);
fileio.chmodSync(fpath, mode);
```
......@@ -1049,7 +1098,6 @@ fstat(fd: number): Promise&lt;Stat&gt;
**示例:**
```js
let fd = fileio.openSync(path);
fileio.fstat(fd).then(function(stat){
console.info("fstat succeed:"+ JSON.stringify(stat));
}).catch(function(err){
......@@ -1153,8 +1201,6 @@ ftruncate(fd: number, len: number, callback:AsyncCallback&lt;void&gt;): void
**示例:**
```js
let fd = fileio.openSync(path);
let len = 5;
fileio.ftruncate(fd, len, function(err){
// do something
});
......@@ -1177,8 +1223,6 @@ ftruncateSync(fd: number, len?: number): void
**示例:**
```js
let fd = fileio.openSync(path);
let len = 5;
fileio.ftruncateSync(fd, len);
```
......@@ -1204,7 +1248,6 @@ truncate(path: string, len?: number): Promise&lt;void&gt;
**示例:**
```js
let len = 5;
fileio.truncate(path, len).then(function(){
console.info("truncate file succeed");
}).catch(function(err){
......@@ -1230,7 +1273,6 @@ truncate(path: string, len: number, callback:AsyncCallback&lt;void&gt;): void
**示例:**
```js
let len = 5;
fileio.truncate(path, len, function(err){
// do something
});
......@@ -1253,7 +1295,6 @@ truncateSync(path: string, len?: number): void
**示例:**
```js
let len = 5;
fileio.truncateSync(path, len);
```
......@@ -1312,7 +1353,7 @@ readText(filePath: string, options: {
**示例:**
```js
fileio.readText(path, { position: pos, length: len, encoding: 'UTF-8' }, function (err, str){
fileio.readText(path, function(err, str){
// do something
});
```
......@@ -1368,7 +1409,7 @@ lstat(path: string): Promise&lt;Stat&gt;
**示例:**
```js
fileio.lstat(path).then(function(stat){
console.info("get link status succeed:"+ stat.rdev);
console.info("get link status succeed:"+ number);
}).catch(function(err){
console.info("get link status failed with error:"+ err);
});
......@@ -1421,6 +1462,69 @@ lstatSync(path:string): Stat
```
## fileio.read<sup>7+</sup>
read(buffer: ArrayBuffer, options?: {
position?: number;
offset?: number;
length?: number;
}): Promise&lt;ReadOut&gt;
从文件读取数据,使用Promise异步回调。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ----------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer | 是 | 用于保存读取到的文件数据的缓冲区。 |
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>约束:offset+length<=buffer.size。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | 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.read<sup>7+</sup>
read(buffer: ArrayBuffer, options: {
position?: number;
offset?: number;
length?: number;
}, callback: AsyncCallback&lt;ReadOut&gt;): void
从文件读取数据,使用callback异步回调。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | 是 | 用于保存读取到的文件数据的缓冲区。 |
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>约束:offset+length<=buffer.size。 |
| callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | 是 | 异步从文件读取数据之后的回调。 |
**示例:**
```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.rename<sup>7+</sup>
......@@ -1444,8 +1548,7 @@ rename(oldPath: string, newPath: string): Promise&lt;void&gt;
**示例:**
```js
let newPath = path +"123";
fileio.rename(path, newPath).then(function() {
fileio.rename(oldPath, newPath).then(function() {
console.info("rename succeed");
}).catch(function(err){
console.info("rename failed with error:"+ err);
......@@ -1470,8 +1573,7 @@ rename(oldPath: string, newPath: string, callback: AsyncCallback&lt;void&gt;): v
**示例:**
```js
let newPath = path +"123";
fileio.rename(path, newPath, function(err){
fileio.rename(oldPath, newPath, function(err){
});
```
......@@ -1492,8 +1594,7 @@ renameSync(oldPath: string, newPath: string): void
**示例:**
```js
let newPath = path +"123";
fileio.renameSync(path, newPath);
fileio.renameSync(oldPath, newPath);
```
......@@ -1517,7 +1618,6 @@ fsync(fd: number): Promise&lt;void&gt;
**示例:**
```js
let fd = fileio.openSync(path);
fileio.fsync(fd).then(function(){
console.info("sync data succeed");
}).catch(function(err){
......@@ -1542,7 +1642,6 @@ fsync(fd: number, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
let fd = fileio.openSync(path);
fileio.fsync(fd, function(err){
// do something
});
......@@ -1564,7 +1663,6 @@ fsyncSync(fd: number): void
**示例:**
```js
let fd = fileio.openSync(path);
fileio.fyncsSync(fd);
```
......@@ -1589,7 +1687,6 @@ fdatasync(fd: number): Promise&lt;void&gt;
**示例:**
```js
let fd = fileio.openSync(path);
fileio.fdatasync(fd).then(function(err) {
console.info("sync data succeed");
}).catch(function(err){
......@@ -1614,7 +1711,6 @@ fdatasync(fd: number, callback:AsyncCallback&lt;void&gt;): void
**示例:**
```js
let fd = fileio.openSync(path);
fileio.fdatasync (fd, function (err) {
// do something
});
......@@ -1636,7 +1732,6 @@ fdatasyncSync(fd: number): void
**示例:**
```js
let fd = fileio.openSync(path);
let stat = fileio.fdatasyncSync(fd);
```
......@@ -1662,8 +1757,7 @@ symlink(target: string, srcPath: string): Promise&lt;void&gt;
**示例:**
```js
let srcPath = "";
fileio.symlink(path, srcPath).then(function() {
fileio.symlink(target, srcPath).then(function() {
console.info("symlink succeed");
}).catch(function(err){
console.info("symlink failed with error:"+ err);
......@@ -1688,8 +1782,7 @@ symlink(target: string, srcPath: string, callback: AsyncCallback&lt;void&gt;): v
**示例:**
```js
let srcPath = "";
fileio.symlink(path, srcPath, function (err) {
fileio.symlink(target, srcPath, function (err) {
// do something
});
```
......@@ -1711,8 +1804,7 @@ symlinkSync(target: string, srcPath: string): void
**示例:**
```js
let srcPath = "";
fileio.symlinkSync(path, srcPath);
fileio.symlinkSync(target, srcPath);
```
......@@ -1765,7 +1857,7 @@ chown(path: string, uid: number, gid: number, callback: AsyncCallback&lt;void&gt
**示例:**
```js
let stat = fileio.statSync(path)
let stat = fileio.statSync(fpath)
fileio.chown(path, stat.uid, stat.gid, function (err){
// do something
});
......@@ -1789,7 +1881,7 @@ chownSync(path: string, uid: number, gid: number): void
**示例:**
```js
let stat = fileio.statSync(path)
let stat = fileio.statSync(fpath)
fileio.chownSync(path, stat.uid, stat.gid);
```
......@@ -1889,8 +1981,6 @@ fchmod(fd: number, mode: number): Promise&lt;void&gt;
**示例:**
```js
let fd = fileio.openSync(path);
let mode = 0o400;
fileio.fchmod(fd, mode).then(function() {
console.info("chmod succeed");
}).catch(function(err){
......@@ -1916,8 +2006,6 @@ fchmod(fd: number, mode: number, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
let fd = fileio.openSync(path);
let mode = 0o400;
fileio.fchmod(fd, mode, function (err) {
// do something
});
......@@ -1940,8 +2028,6 @@ fchmodSync(fd: number, mode: number): void
**示例:**
```js
let fd = fileio.openSync(path);
let mode = 0o400;
fileio.fchmodSync(fd, mode);
```
......@@ -1992,7 +2078,6 @@ createStream(path: string, mode: string, callback: AsyncCallback&lt;Stream&gt;):
**示例:**
```js
let mode = 0o400;
fileio.createStream(path, mode, function(err, stream){
// do something
});
......@@ -2045,8 +2130,6 @@ fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt;
**示例:**
```js
let fd = fileio.openSync(path);
let mode = 0o400;
fileio.fdopenStream(fd, mode).then(function(stream){
console.info("openStream succeed");
}).catch(function(err){
......@@ -2072,8 +2155,6 @@ fdopenStream(fd: number, mode: string, callback: AsyncCallback&lt;Stream&gt;): v
**示例:**
```js
let fd = fileio.openSync(path);
let mode = 0o400;
fileio.fdopenStream(fd, mode, function (err, stream) {
// do something
});
......@@ -2101,7 +2182,6 @@ fdopenStreamSync(fd: number, mode: string): Stream
**示例:**
```js
let fd = fileio.openSync(path);
let ss = fileio.fdopenStreamSync(fd, "r+");
```
......@@ -2128,7 +2208,6 @@ fchown(fd: number, uid: number, gid: number): Promise&lt;void&gt;
**示例:**
```js
let fd = fileio.openSync(path);
let stat = fileio.statSync(path);
fileio.fchown(fd, stat.uid, stat.gid).then(function() {
console.info("chown succeed");
......@@ -2156,8 +2235,7 @@ fchown(fd: number, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;
**示例:**
```js
let fd = fileio.openSync(path);
let stat = fileio.statSync(path);
let stat = fileio.statSync(fpath);
fileio.fchown(fd, stat.uid, stat.gid, function (err){
// do something
});
......@@ -2181,8 +2259,7 @@ fchownSync(fd: number, uid: number, gid: number): void
**示例:**
```js
let fd = fileio.openSync(path);
let stat = fileio.statSync(path);
let stat = fileio.statSync(fpath);
fileio.fchownSync(fd, stat.uid, stat.gid);
```
......@@ -2287,8 +2364,6 @@ createWatcher(filename: string, events: number, callback: AsyncCallback&lt;numbe
**示例:**
```js
let filename = path +"/test.txt";
let events = 1;
fileio.createWatcher(filename, events, function(watcher){
// do something
});
......@@ -2423,7 +2498,7 @@ isFile(): boolean
**示例:**
```js
let isFile = fileio.statSync(path).isFile();
let isFile = fileio.statSync(fpath).isFile();
```
......@@ -2525,7 +2600,7 @@ close(): Promise&lt;void&gt;
**示例:**
```js
let ss= fileio.createStreamSync(path,"r+");
let ss= fileio.createStreamSync(path);
ss.close().then(function(){
console.info("close fileStream succeed");
}).catch(function(err){
......@@ -2566,7 +2641,7 @@ closeSync(): void
**示例:**
```js
let ss= fileio.createStreamSync(path,"r+");
let ss= fileio.createStreamSync(path);
ss.closeSync();
```
......@@ -2586,7 +2661,7 @@ flush(): Promise&lt;void&gt;
**示例:**
```js
let ss= fileio.createStreamSync(path,"r+");
let ss= fileio.createStreamSync(path);
ss.flush().then(function (){
console.info("flush succeed");
}).catch(function(err){
......@@ -2610,7 +2685,7 @@ flush(callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
let ss= fileio.createStreamSync(path,"r+");
let ss= fileio.createStreamSync(path);
ss.flush(function (err) {
// do something
});
......@@ -2627,7 +2702,7 @@ flushSync(): void
**示例:**
```js
let ss= fileio.createStreamSync(path,"r+");
let ss= fileio.createStreamSync(path);
ss.flushSync();
```
......@@ -2658,7 +2733,7 @@ write(buffer: ArrayBuffer | string, options?: {
**示例:**
```js
let ss= fileio.createStreamSync(path, "r+");
let ss= fileio.createStreamSync(fpath, "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){
......@@ -2689,7 +2764,7 @@ write(buffer: ArrayBuffer | string, options: {
**示例:**
```js
let ss= fileio.createStreamSync(path, "r+");
let ss= fileio.createStreamSync(fpath, "r+");
ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) {
if (bytesWritten) {
// do something
......@@ -2725,7 +2800,7 @@ writeSync(buffer: ArrayBuffer | string, options?: {
**示例:**
```js
let ss= fileio.createStreamSync(path,"r+");
let ss= fileio.createStreamSync(fpath,"r+");
let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'});
```
......@@ -2755,10 +2830,10 @@ read(buffer: ArrayBuffer, options?: {
**示例:**
```js
let ss = fileio.createStreamSync(path, "r+");
let ss = fileio.createStreamSync(fpath, "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);
});
......@@ -2786,7 +2861,7 @@ read(buffer: ArrayBuffer, options: {
**示例:**
```js
let ss = fileio.createStreamSync(path, "r+");
let ss = fileio.createStreamSync(fpath, "r+");
ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) {
if (readOut) {
console.info("read data succeed");
......@@ -2823,7 +2898,7 @@ readSync(buffer: ArrayBuffer, options?: {
**示例:**
```js
let ss = fileio.createStreamSync(path, "r+");
let ss = fileio.createStreamSync(fpath, "r+");
let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5});
```
......@@ -2848,7 +2923,7 @@ read(): Promise&lt;Dirent&gt;
**示例:**
```js
dir = fileio.opendirSync(path);
let dir = fileio.opendirSync(path);
dir.read().then(function (dirent){
console.log("read succeed:"+JSON.stringify(dirent));
}).catch(function(err){
......@@ -2872,7 +2947,7 @@ read(callback: AsyncCallback&lt;Dirent&gt;): void
**示例:**
```js
dir = fileio.opendirSync(path);
let dir = fileio.opendirSync(path);
dir.read(function (err, dirent) {
if (dirent) {
// do something
......@@ -2897,11 +2972,45 @@ readSync(): Dirent
**示例:**
```js
dir = fileio.opendirSync(path);
let dir = fileio.opendirSync(path);
let dirent = dir.readSync();
```
### close<sup>7+</sup>
close(): Promise&lt;void&gt;
异步关闭目录,使用promise形式返回结果。目录被关闭后,Dir中持有的文件描述将被释放,后续将无法从Dir中读取目录项。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**示例:**
```js
let dir = fileio.opendirSync(path);
dir.close().then(function(err){
console.info("close dir successfully");
});
```
### close<sup>7+</sup>
close(callback: AsyncCallback&lt;void&gt;): 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
......@@ -2912,7 +3021,7 @@ closeSync(): void
**示例:**
```js
dir = fileio.opendirSync(path);
let dir = fileio.opendirSync(path);
dir.closeSync();
```
......@@ -2945,7 +3054,7 @@ isBlockDevice(): boolean
**示例:**
```js
dir = fileio.opendirSync(path);
let dir = fileio.opendirSync(path);
let isBLockDevice = dir.readSync().isBlockDevice();
```
......@@ -2965,7 +3074,7 @@ isCharacterDevice(): boolean
**示例:**
```js
dir = fileio.opendirSync(path);
let dir = fileio.opendirSync(path);
let isCharacterDevice = dir.readSync().isCharacterDevice();
```
......@@ -2985,7 +3094,7 @@ isDirectory(): boolean
**示例:**
```js
dir = fileio.opendirSync(path);
let dir = fileio.opendirSync(path);
let isDirectory = dir.readSync().isDirectory();
```
......@@ -3005,7 +3114,7 @@ isFIFO(): boolean
**示例:**
```js
dir = fileio.opendirSync(path);
let dir = fileio.opendirSync(path);
let isFIFO = dir.readSync().isFIFO();
```
......@@ -3025,7 +3134,7 @@ isFile(): boolean
**示例:**
```js
dir = fileio.opendirSync(path);
let dir = fileio.opendirSync(path);
let isFile = dir.readSync().isFile();
```
......@@ -3045,7 +3154,7 @@ isSocket(): boolean
**示例:**
```js
dir = fileio.opendirSync(path);
let dir = fileio.opendirSync(dpath);
let isSocket = dir.readSync().isSocket();
```
......@@ -3065,6 +3174,6 @@ isSymbolicLink(): boolean
**示例:**
```js
dir = fileio.opendirSync(path);
let dir = fileio.opendirSync(path);
let isSymbolicLink = dir.readSync().isSymbolicLink();
```
......@@ -18,7 +18,7 @@ getRoot(options? : {dev? : DevInfo}) : Promise&lt;FileInfo[]&gt;
以异步方法获取第一层相册,目录信息。使用promise形式返回结果。
**系统能力**:SystemCapability.FileManagement.FileManagerService
**系统能力**:SystemCapability.FileManagement.UserFileService
- 参数
| 参数名 | 类型 | 必填 | 说明 |
......@@ -51,7 +51,7 @@ getRoot(options? : {dev? : DevInfo}, callback : AsyncCallback&lt;FileInfo[]&gt;)
以异步方法获取第一层相册,目录信息。使用callback形式返回结果。
**系统能力**:SystemCapability.FileManagement.FileManagerService
**系统能力**:SystemCapability.FileManagement.UserFileService
- 参数
......@@ -84,7 +84,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
以异步方法获取第二层相册,文件信息。使用promise形式返回结果。
**系统能力**:SystemCapability.FileManagement.FileManagerService
**系统能力**:SystemCapability.FileManagement.UserFileService
- 参数
| 参数名 | 类型 | 必填 | 说明 |
......@@ -133,7 +133,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
以异步方法获取第二层相册,文件信息。使用callback形式返回结果。
**系统能力**:SystemCapability.FileManagement.FileManagerService
**系统能力**:SystemCapability.FileManagement.UserFileService
- 参数
......@@ -187,7 +187,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
以异步方法创建文件到指定路径,返回文件uri。使用promise形式返回结果。
**系统能力**:SystemCapability.FileManagement.FileManagerService
**系统能力**:SystemCapability.FileManagement.UserFileService
- 参数
| 参数名 | 类型 | 必填 | 说明 |
......@@ -230,7 +230,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
以异步方法创建文件到指定路径,返回文件uri。使用callback形式返回结果。
**系统能力**:SystemCapability.FileManagement.FileManagerService
**系统能力**:SystemCapability.FileManagement.UserFileService
- 参数
......@@ -269,7 +269,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
## FileInfo
文件信息类型,通过getRoot, listFile等接口返回的类型。
**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.FileManagerService。
**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.UserFileService。
### 属性
......@@ -286,7 +286,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
设备类型,配置接口访问的设备类型。
**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.FileManagerService。
**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.UserFileService。
### 属性
......
......@@ -23,18 +23,18 @@ let path = context.getFilesDir();
## securityLabel.setSecurityLabel
setSecurityLabel(path:string, dataLevel:string):Promise&lt;void&gt;
setSecurityLabel(path:string, type:dataLevel):Promise&lt;void&gt;
以异步方法设置数据标签,以promise形式返回结果。
**系统能力**:SystemCapability.FileManagement.File.DistributedFile
**系统能力**:SystemCapability.FileManagement.File.FileIO
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | -------------------------------------------- |
| path | string | 是 | 文件路径 |
| dataLevel | string | 是 | 文件等级属性,只支持"s0","s1","s2","s3","s4" |
| type | dataLevel | 是 | 文件等级属性,只支持"s0","s1","s2","s3","s4" |
**返回值:**
......@@ -45,8 +45,8 @@ setSecurityLabel(path:string, dataLevel:string):Promise&lt;void&gt;
**示例:**
```js
let dataLevel = "s4";
securityLabel.setSecurityLabel(path, dataLevel).then(function(){
let type = "s4";
securityLabel.setSecurityLabel(path, type).then(function(){
console.info("setSecurityLabel successfully");
}).catch(function(error){
console.info("setSecurityLabel failed with error:" + error);
......@@ -55,25 +55,25 @@ setSecurityLabel(path:string, dataLevel:string):Promise&lt;void&gt;
## securityLabel.setSecurityLabel
setSecurityLabel(path:string, dataLevel:string, callback: AsyncCallback&lt;void&gt;):void
setSecurityLabel(path:string, type:dataLevel, callback: AsyncCallback&lt;void&gt;):void
以异步方法设置数据标签,以callback形式返回结果。
**系统能力**:SystemCapability.FileManagement.File.DistributedFile
**系统能力**:SystemCapability.FileManagement.File.FileIO
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | -------------------------------------------- |
| path | string | 是 | 文件路径 |
| dataLevel | string | 是 | 文件等级属性,只支持"s0","s1","s2","s3","s4" |
| type | dataLevel | 是 | 文件等级属性,只支持"s0","s1","s2","s3","s4" |
| callback | AsyncCallback&lt;void&gt; | 是 | 是否设置数据标签之后的回调 |
**示例:**
```js
let dataLevel = "s4";
securityLabel.setSecurityLabel(path, dataLevel, function(error){
let type = "s4";
securityLabel.setSecurityLabel(path, type, function(error){
console.info("setSecurityLabel:" + JSON.stringify(error));
});
```
......@@ -83,20 +83,20 @@ setSecurityLabelSync(path:string, dataLevel:string):void
以同步方法设置数据标签。
**系统能力**:SystemCapability.FileManagement.File.DistributedFile
**系统能力**:SystemCapability.FileManagement.File.FileIO
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | -------------------------------------------- |
| path | string | 是 | 文件路径 |
| dataLevel | string | 是 | 文件等级属性,只支持"s0","s1","s2","s3","s4" |
| type | dataLevel | 是 | 文件等级属性,只支持"s0","s1","s2","s3","s4" |
**示例:**
```js
let dataLevel = "s4";
securityLabel.setSecurityLabelSync(path, dataLevel);
let type = "s4";
securityLabel.setSecurityLabelSync(path, type);
```
## securityLabel.getSecurityLabel
......@@ -105,7 +105,7 @@ getSecurityLabel(path:string):Promise&lt;string&gt;
异步方法获取数据标签,以promise形式返回结果。
**系统能力**:SystemCapability.FileManagement.File.DistributedFile
**系统能力**:SystemCapability.FileManagement.File.FileIO
**参数:**
......@@ -122,9 +122,9 @@ getSecurityLabel(path:string):Promise&lt;string&gt;
**示例:**
```js
let dataLevel = "s4";
securityLabel.getSecurityLabel(path).then(function(dataLevel){
console.log("getSecurityLabel successfully:" + dataLevel);
let type = "s4";
securityLabel.getSecurityLabel(path).then(function(type){
console.log("getSecurityLabel successfully:" + type);
}).catch(function(error){
console.log("getSecurityLabel failed with error:" + error);
});
......@@ -136,7 +136,7 @@ getSecurityLabel(path:string, callback:AsyncCallback&lt;string&gt;): void
异步方法获取数据标签,以callback形式返回结果。
**系统能力**:SystemCapability.FileManagement.File.DistributedFile
**系统能力**:SystemCapability.FileManagement.File.FileIO
**参数:**
......@@ -148,9 +148,9 @@ getSecurityLabel(path:string, callback:AsyncCallback&lt;string&gt;): void
**示例:**
```js
let dataLevel = "s4";
securityLabel.getSecurityLabel(path,function(error, dataLevel){
console.log("getSecurityLabel successfully:" + dataLevel);
let type = "s4";
securityLabel.getSecurityLabel(path,function(error, type){
console.log("getSecurityLabel successfully:" + type);
});
```
## securityLabel.getSecurityLabelSync
......@@ -159,7 +159,7 @@ getSecurityLabelSync(path:string):string
以同步方法获取数据标签。
**系统能力**:SystemCapability.FileManagement.File.DistributedFile
**系统能力**:SystemCapability.FileManagement.File.FileIO
**参数:**
......
......@@ -23,7 +23,7 @@ getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**该接口为系统接口,三方应用不支持调用
该接口为系统接口,三方应用不支持调用
- 参数
......@@ -58,7 +58,7 @@ getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):v
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**该接口为系统接口,三方应用不支持调用
该接口为系统接口,三方应用不支持调用
- 参数
......@@ -89,7 +89,7 @@ getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**该接口为系统接口,三方应用不支持调用
该接口为系统接口,三方应用不支持调用
- 参数
......@@ -125,7 +125,7 @@ getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):vo
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**该接口为系统接口,三方应用不支持调用
该接口为系统接口,三方应用不支持调用
- 参数
......@@ -154,7 +154,7 @@ getBundleStats(packageName: string): Promise&lt;BundleStats&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**该接口为系统接口,三方应用不支持调用
该接口为系统接口,三方应用不支持调用
- 参数
......@@ -189,7 +189,7 @@ getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;)
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**该接口为系统接口,三方应用不支持调用
该接口为系统接口,三方应用不支持调用
- 参数
......@@ -259,6 +259,7 @@ getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void
## BundleStats<sup>9+</sup>
**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics。
该接口为系统接口,三方应用不支持调用
- 属性
......@@ -281,7 +282,7 @@ getTotalSize(): Promise<number>
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**该接口为系统接口,三方应用不支持调用
该接口为系统接口,三方应用不支持调用
- 返回值
......@@ -306,7 +307,7 @@ getTotalSize(callback: AsyncCallback<number>): void
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**该接口为系统接口,三方应用不支持调用
该接口为系统接口,三方应用不支持调用
- 参数
......@@ -334,7 +335,7 @@ getFreeSize(): Promise<number>
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**该接口为系统接口,三方应用不支持调用
该接口为系统接口,三方应用不支持调用
- 返回值
......@@ -360,7 +361,7 @@ getFreeSize(callback: AsyncCallback<number>): void
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**该接口为系统接口,三方应用不支持调用
该接口为系统接口,三方应用不支持调用
- 参数
......@@ -389,7 +390,7 @@ getSystemSize(): Promise&lt;number&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**该接口为系统接口,三方应用不支持调用
该接口为系统接口,三方应用不支持调用
- 返回值
......@@ -417,7 +418,7 @@ getSystemSize(callback:AsyncCallback&lt;number&gt;):void
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**该接口为系统接口,三方应用不支持调用
该接口为系统接口,三方应用不支持调用
- 参数
......@@ -438,7 +439,7 @@ getSystemSize(callback:AsyncCallback&lt;number&gt;):void
## storagestatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId?: string): Promise&lt;StorageStats&gt;
getUserStorageStats(userId?: number): Promise&lt;StorageStats&gt;
异步获取用户各类别数据大小,以promise方式返回。
......@@ -446,7 +447,7 @@ getUserStorageStats(userId?: string): Promise&lt;StorageStats&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**该接口为系统接口,三方应用不支持调用
该接口为系统接口,三方应用不支持调用
- 参数
......@@ -473,7 +474,7 @@ getUserStorageStats(userId?: string): Promise&lt;StorageStats&gt;
## storagestatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId?: string, callback:AsyncCallback&lt;StorageStats&gt;):void
getUserStorageStats(userId?: number, callback:AsyncCallback&lt;StorageStats&gt;):void
异步获取用户各类别数据大小,以callback方式返回。
......@@ -481,7 +482,7 @@ getUserStorageStats(userId?: string, callback:AsyncCallback&lt;StorageStats&gt;)
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**该接口为系统接口,三方应用不支持调用
该接口为系统接口,三方应用不支持调用
- 参数
......@@ -505,7 +506,7 @@ getUserStorageStats(userId?: string, callback:AsyncCallback&lt;StorageStats&gt;)
## StorageStats<sup>9+</sup>
**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics。
该接口为系统接口,三方应用不支持调用
- 属性
| 名称 | 类型 | 说明 |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册