Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
b8a36ab1
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b8a36ab1
编写于
6月 09, 2022
作者:
H
haonan_7
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix fileIO.md
Signed-off-by:
N
haonan_7
<
haonan2@huawei.com
>
上级
3902cc6c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
183 addition
and
179 deletion
+183
-179
zh-cn/application-dev/reference/apis/js-apis-fileio.md
zh-cn/application-dev/reference/apis/js-apis-fileio.md
+183
-179
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-fileio.md
浏览文件 @
b8a36ab1
...
@@ -3,7 +3,13 @@
...
@@ -3,7 +3,13 @@
>  **说明:**
>  **说明:**
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
该模块提供文件存储相关的常用功能:向应用程序提供用于IO的JS接口,包括用于管理文件的基本文件接口,用于管理目录的基本目录接口,用于获取文件信息的统计接口,用于流式读写文件的流式接口。
该模块提供文件存储相关的常用功能,向应用程序提供用于IO的JS接口,包括:
-
用于管理文件的基本文件接口
-
用于管理目录的基本目录接口
-
用于获取文件信息的统计接口
-
用于流式读写文件的流式接口
## 导入模块
## 导入模块
...
@@ -14,10 +20,8 @@ import fileio from '@ohos.fileio';
...
@@ -14,10 +20,8 @@ import fileio from '@ohos.fileio';
## 使用说明
## 使用说明
使用该功能模块对文件/目录进行操作前,需要先获取其应用沙箱路径,获取方式及其接口用法请参考:
[
Context模块的接口getOrCreateLocalDir
](
js-apis-Context.md
)
。
使用该功能模块对文件/目录进行操作前,需要先获取其应用沙箱绝对路径,“文件/目录应用沙箱路径”=“应用目录路径”+“文件/目录名”。
应用目录路径dir的获取方式及对应的接口用法请参考:
[
Context模块的接口getOrCreateLocalDir
](
js-apis-Context.md
)
。
“文件/目录应用沙箱路径”=“应用目录路径”+“文件/目录名”
通过上述接口获取到应用目录路径dir,文件名为“xxx.txt”,文件所在应用沙箱路径为:
通过上述接口获取到应用目录路径dir,文件名为“xxx.txt”,文件所在应用沙箱路径为:
```
js
```
js
...
@@ -37,7 +41,7 @@ let fd = fileio.openSync(path);
...
@@ -37,7 +41,7 @@ let fd = fileio.openSync(path);
stat(path: string): Promise
<
Stat
>
stat(path: string): Promise
<
Stat
>
以异步方法获取文件信息,使用promise形式返回结果
。
获取文件信息,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -51,12 +55,12 @@ stat(path: string): Promise<Stat>
...
@@ -51,12 +55,12 @@ stat(path: string): Promise<Stat>
| 类型 | 说明 |
| 类型 | 说明 |
| ---------------------------- | ---------- |
| ---------------------------- | ---------- |
| Promise
<
[Stat](#stat)
>
|
表示
文件的具体信息。 |
| Promise
<
[Stat](#stat)
>
|
Promise对象。返回
文件的具体信息。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
stat
(
path
).
then
(
function
(
stat
){
fileio
.
stat
(
path
).
then
(
function
(
stat
){
console
.
info
(
"
getFileInfo succe
ssfully
:
"
+
JSON
.
stringify
(
stat
));
console
.
info
(
"
getFileInfo succe
ed
:
"
+
JSON
.
stringify
(
stat
));
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
getFileInfo failed with error:
"
+
err
);
console
.
info
(
"
getFileInfo failed with error:
"
+
err
);
});
});
...
@@ -67,7 +71,7 @@ stat(path: string): Promise<Stat>
...
@@ -67,7 +71,7 @@ stat(path: string): Promise<Stat>
stat(path:string, callback:AsyncCallback
<
Stat
>
): void
stat(path:string, callback:AsyncCallback
<
Stat
>
): void
以异步方法获取文件信息,使用callback形式返回结果
。
获取文件信息,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -115,7 +119,7 @@ statSync(path:string): Stat
...
@@ -115,7 +119,7 @@ statSync(path:string): Stat
opendir(path: string): Promise
<
Dir
>
opendir(path: string): Promise
<
Dir
>
以异步方法打开文件目录,使用promise形式返回结果
。
打开文件目录,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -127,12 +131,12 @@ opendir(path: string): Promise<Dir>
...
@@ -127,12 +131,12 @@ opendir(path: string): Promise<Dir>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| -------------------------- | -------- |
| -------------------------- | -------- |
| Promise
<
[Dir](#dir)
>
| 返回Dir对象。 |
| Promise
<
[Dir](#dir)
>
|
Promise对象。
返回Dir对象。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
opendir
(
path
).
then
(
function
(
dir
){
fileio
.
opendir
(
path
).
then
(
function
(
dir
){
console
.
info
(
"
opendir succe
ssfully
:
"
+
JSON
.
stringify
(
dir
));
console
.
info
(
"
opendir succe
ed
:
"
+
JSON
.
stringify
(
dir
));
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
opendir failed with error:
"
+
err
);
console
.
info
(
"
opendir failed with error:
"
+
err
);
});
});
...
@@ -143,7 +147,7 @@ opendir(path: string): Promise<Dir>
...
@@ -143,7 +147,7 @@ opendir(path: string): Promise<Dir>
opendir(path: string, callback: AsyncCallback
<
Dir
>
): void
opendir(path: string, callback: AsyncCallback
<
Dir
>
): void
以异步方法打开文件目录,使用callback形式返回结果
。
打开文件目录,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -195,7 +199,7 @@ opendirSync(path: string): Dir
...
@@ -195,7 +199,7 @@ opendirSync(path: string): Dir
access(path: string, mode?: number): Promise
<
void
>
access(path: string, mode?: number): Promise
<
void
>
以异步方法检查当前进程是否可访问某文件,使用promise形式返回结果
。
检查当前进程是否可访问某文件,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -209,12 +213,12 @@ access(path: string, mode?: number): Promise<void>
...
@@ -209,12 +213,12 @@ access(path: string, mode?: number): Promise<void>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果。本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
access
(
path
).
then
(
function
()
{
fileio
.
access
(
path
).
then
(
function
()
{
console
.
info
(
"
access succe
ssfully
"
);
console
.
info
(
"
access succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
access failed with error:
"
+
err
);
console
.
info
(
"
access failed with error:
"
+
err
);
});
});
...
@@ -225,7 +229,7 @@ access(path: string, mode?: number): Promise<void>
...
@@ -225,7 +229,7 @@ access(path: string, mode?: number): Promise<void>
access(path: string, mode: number, callback: AsyncCallback
<
void
>
): void
access(path: string, mode: number, callback: AsyncCallback
<
void
>
): void
以异步方法检查当前进程是否可访问某文件,使用callback形式返回结果
。
检查当前进程是否可访问某文件,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -272,7 +276,7 @@ accessSync(path: string, mode?: number): void
...
@@ -272,7 +276,7 @@ accessSync(path: string, mode?: number): void
close(fd: number):Promise
<
void
>
close(fd: number):Promise
<
void
>
以异步方法关闭文件,使用promise形式返回结果
。
关闭文件,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -284,13 +288,13 @@ close(fd: number):Promise<void>
...
@@ -284,13 +288,13 @@ close(fd: number):Promise<void>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果。本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
let
fd
=
fileio
.
openSync
(
path
);
fileio
.
close
(
fd
).
then
(
function
(){
fileio
.
close
(
fd
).
then
(
function
(){
console
.
info
(
"
close file succe
ssfully
"
);
console
.
info
(
"
close file succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
close file failed with error:
"
+
err
);
console
.
info
(
"
close file failed with error:
"
+
err
);
});
});
...
@@ -301,7 +305,7 @@ close(fd: number):Promise<void>
...
@@ -301,7 +305,7 @@ close(fd: number):Promise<void>
close(fd: number, callback:AsyncCallback
<
void
>
): void
close(fd: number, callback:AsyncCallback
<
void
>
): void
以异步方法关闭文件,使用callback形式返回结果
。
关闭文件,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -343,19 +347,19 @@ closeSync(fd: number): void
...
@@ -343,19 +347,19 @@ closeSync(fd: number): void
close(): Promise
<
void
>
close(): Promise
<
void
>
以异步方法关闭文件流,使用promise形式返回结果
。
关闭文件流,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果。本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
close
().
then
(
function
(){
fileio
.
close
().
then
(
function
(){
console
.
info
(
"
close file stream succe
ssfully
"
);
console
.
info
(
"
close file stream succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
close file stream failed with error:
"
+
err
);
console
.
info
(
"
close file stream failed with error:
"
+
err
);
});
});
...
@@ -366,7 +370,7 @@ close(): Promise<void>
...
@@ -366,7 +370,7 @@ close(): Promise<void>
close(callback: AsyncCallback
<
void
>
): void
close(callback: AsyncCallback
<
void
>
): void
以异步方法关闭文件流,使用callback形式返回结果
。
关闭文件流,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -387,7 +391,7 @@ close(callback: AsyncCallback<void>): void
...
@@ -387,7 +391,7 @@ close(callback: AsyncCallback<void>): void
copyFile(src:string | number, dest:string | number, mode?:number):Promise
<
void
>
copyFile(src:string | number, dest:string | number, mode?:number):Promise
<
void
>
以异步方法复制文件,使用promise形式返回结果
。
复制文件,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -401,12 +405,12 @@ copyFile(src:string | number, dest:string | number, mode?:number):Promise<voi
...
@@ -401,12 +405,12 @@ copyFile(src:string | number, dest:string | number, mode?:number):Promise<voi
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果。本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
copyFile
(
src
,
dest
).
then
(
function
(){
fileio
.
copyFile
(
src
,
dest
).
then
(
function
(){
console
.
info
(
"
copyFile succe
ssfully
"
);
console
.
info
(
"
copyFile succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
copyFile failed with error:
"
+
err
);
console
.
info
(
"
copyFile failed with error:
"
+
err
);
});
});
...
@@ -417,7 +421,7 @@ copyFile(src:string | number, dest:string | number, mode?:number):Promise<voi
...
@@ -417,7 +421,7 @@ copyFile(src:string | number, dest:string | number, mode?:number):Promise<voi
copyFile(src: string | number, dest: string | number, mode: number, callback: AsyncCallback
<
void
>
): void
copyFile(src: string | number, dest: string | number, mode: number, callback: AsyncCallback
<
void
>
): void
以异步方法复制文件,使用callback形式返回结果
。
复制文件,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -462,7 +466,7 @@ copyFileSync(src: string | number, dest: string | number, mode?: number): void
...
@@ -462,7 +466,7 @@ copyFileSync(src: string | number, dest: string | number, mode?: number): void
mkdir(path:string, mode?: number): Promise
<
void
>
mkdir(path:string, mode?: number): Promise
<
void
>
以异步方法创建目录,使用promise形式返回结果
。
创建目录,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -475,12 +479,12 @@ mkdir(path:string, mode?: number): Promise<void>
...
@@ -475,12 +479,12 @@ mkdir(path:string, mode?: number): Promise<void>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果。本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
mkdir
(
path
).
then
(
function
()
{
fileio
.
mkdir
(
path
).
then
(
function
()
{
console
.
info
(
"
mkdir succe
ssfully
"
);
console
.
info
(
"
mkdir succe
ed
"
);
}).
catch
(
function
(
error
){
}).
catch
(
function
(
error
){
console
.
info
(
"
mkdir failed with error:
"
+
error
);
console
.
info
(
"
mkdir failed with error:
"
+
error
);
});
});
...
@@ -491,7 +495,7 @@ mkdir(path:string, mode?: number): Promise<void>
...
@@ -491,7 +495,7 @@ mkdir(path:string, mode?: number): Promise<void>
mkdir(path: string, mode: number, callback: AsyncCallback
<
void
>
): void
mkdir(path: string, mode: number, callback: AsyncCallback
<
void
>
): void
以异步方法创建目录,使用callback形式返回结果
。
创建目录,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -505,7 +509,7 @@ mkdir(path: string, mode: number, callback: AsyncCallback<void>): void
...
@@ -505,7 +509,7 @@ mkdir(path: string, mode: number, callback: AsyncCallback<void>): void
**示例:**
**示例:**
```
js
```
js
fileio
.
mkdir
(
path
,
function
(
err
)
{
fileio
.
mkdir
(
path
,
function
(
err
)
{
console
.
info
(
"
mkdir succe
ssfully
"
);
console
.
info
(
"
mkdir succe
ed
"
);
});
});
```
```
...
@@ -534,7 +538,7 @@ mkdirSync(path: string, mode?: number): void
...
@@ -534,7 +538,7 @@ mkdirSync(path: string, mode?: number): void
open(path: string, flags?: number, mode?: number): Promise
<
number
>
open(path: string, flags?: number, mode?: number): Promise
<
number
>
以异步的方法打开文件,使用promise形式返回结果
。
打开文件,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -548,12 +552,12 @@ open(path: string, flags?: number, mode?: number): Promise<number>
...
@@ -548,12 +552,12 @@ open(path: string, flags?: number, mode?: number): Promise<number>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| --------------------- | ----------- |
| --------------------- | ----------- |
| Promise
<
number
>
| 打开文件的文件描述符。 |
| Promise
<
number
>
|
Promise对象。返回
打开文件的文件描述符。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
open
(
path
,
0o1
,
0o0200
).
then
(
function
(
number
){
fileio
.
open
(
path
,
0o1
,
0o0200
).
then
(
function
(
number
){
console
.
info
(
"
open file succe
ssfully
"
);
console
.
info
(
"
open file succe
ed
"
);
}).
catch
(
function
(
error
){
}).
catch
(
function
(
error
){
console
.
info
(
"
open file failed with error:
"
+
err
);
console
.
info
(
"
open file failed with error:
"
+
err
);
});
});
...
@@ -564,7 +568,7 @@ open(path: string, flags?: number, mode?: number): Promise<number>
...
@@ -564,7 +568,7 @@ open(path: string, flags?: number, mode?: number): Promise<number>
open(path: string, flags: number, mode: number, callback: AsyncCallback
<
number
>
): void
open(path: string, flags: number, mode: number, callback: AsyncCallback
<
number
>
): void
以异步的方法打开文件,使用callback形式返回结果
。
打开文件,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -618,7 +622,7 @@ read(fd: number, buffer: ArrayBuffer, options?: {
...
@@ -618,7 +622,7 @@ read(fd: number, buffer: ArrayBuffer, options?: {
position?: number;
position?: number;
}): Promise
<
ReadOut
>
}): Promise
<
ReadOut
>
以异步方法从文件读取数据,使用promise形式返回结果
。
从文件读取数据,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -633,14 +637,14 @@ read(fd: number, buffer: ArrayBuffer, options?: {
...
@@ -633,14 +637,14 @@ read(fd: number, buffer: ArrayBuffer, options?: {
| 类型 | 说明 |
| 类型 | 说明 |
| ---------------------------------- | ------ |
| ---------------------------------- | ------ |
| Promise
<
[ReadOut](#readout)
>
| 读取的结果。 |
| Promise
<
[ReadOut](#readout)
>
|
Promise对象。返回
读取的结果。 |
**示例:**
**示例:**
```
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 succe
ssfully
"
);
console
.
info
(
"
read file data succe
ed
"
);
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
(
error
){
console
.
info
(
"
read file data failed with error:
"
+
error
);
console
.
info
(
"
read file data failed with error:
"
+
error
);
...
@@ -656,7 +660,7 @@ read(fd: number, buffer: ArrayBuffer, options: {
...
@@ -656,7 +660,7 @@ read(fd: number, buffer: ArrayBuffer, options: {
position?: number;
position?: number;
}, callback: AsyncCallback
<
ReadOut
>
): void
}, callback: AsyncCallback
<
ReadOut
>
): void
以异步方法从文件读取数据,使用callback形式返回结果
。
从文件读取数据,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -674,7 +678,7 @@ read(fd: number, buffer: ArrayBuffer, options: {
...
@@ -674,7 +678,7 @@ read(fd: number, buffer: ArrayBuffer, options: {
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 succe
ssfully
"
);
console
.
info
(
"
read file data succe
ed
"
);
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
}
}
});
});
...
@@ -717,7 +721,7 @@ readSync(fd: number, buffer: ArrayBuffer, options?: {
...
@@ -717,7 +721,7 @@ readSync(fd: number, buffer: ArrayBuffer, options?: {
rmdir(path: string): Promise
<
void
>
rmdir(path: string): Promise
<
void
>
以异步方法删除目录,使用promise形式返回结果
。
删除目录,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -729,12 +733,12 @@ rmdir(path: string): Promise<void>
...
@@ -729,12 +733,12 @@ rmdir(path: string): Promise<void>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果。本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
rmdir
(
path
).
then
(
function
()
{
fileio
.
rmdir
(
path
).
then
(
function
()
{
console
.
info
(
"
rmdir succe
ssfully
"
);
console
.
info
(
"
rmdir succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
rmdir failed with error:
"
+
err
);
console
.
info
(
"
rmdir failed with error:
"
+
err
);
});
});
...
@@ -745,7 +749,7 @@ rmdir(path: string): Promise<void>
...
@@ -745,7 +749,7 @@ rmdir(path: string): Promise<void>
rmdir(path: string, callback:AsyncCallback
<
void
>
): void
rmdir(path: string, callback:AsyncCallback
<
void
>
): void
以异步方法删除目录,使用callback形式返回结果
。
删除目录,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -759,7 +763,7 @@ rmdir(path: string, callback:AsyncCallback<void>): void
...
@@ -759,7 +763,7 @@ rmdir(path: string, callback:AsyncCallback<void>): void
```
js
```
js
fileio
.
rmdir
(
path
,
function
(
err
){
fileio
.
rmdir
(
path
,
function
(
err
){
// do something
// do something
console
.
info
(
"
rmdir succe
ssfully
"
);
console
.
info
(
"
rmdir succe
ed
"
);
});
});
```
```
...
@@ -787,7 +791,7 @@ rmdirSync(path: string): void
...
@@ -787,7 +791,7 @@ rmdirSync(path: string): void
unlink(path:string): Promise
<
void
>
unlink(path:string): Promise
<
void
>
以异步方法删除文件,使用promise形式返回结果
。
删除文件,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -799,12 +803,12 @@ unlink(path:string): Promise<void>
...
@@ -799,12 +803,12 @@ unlink(path:string): Promise<void>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果。本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
unlink
(
path
).
then
(
function
(){
fileio
.
unlink
(
path
).
then
(
function
(){
console
.
info
(
"
remove file succe
ssfully
"
);
console
.
info
(
"
remove file succe
ed
"
);
}).
catch
(
function
(
error
){
}).
catch
(
function
(
error
){
console
.
info
(
"
remove file failed with error:
"
+
error
);
console
.
info
(
"
remove file failed with error:
"
+
error
);
});
});
...
@@ -815,7 +819,7 @@ unlink(path:string): Promise<void>
...
@@ -815,7 +819,7 @@ unlink(path:string): Promise<void>
unlink(path:string, callback:AsyncCallback
<
void
>
): void
unlink(path:string, callback:AsyncCallback
<
void
>
): void
以异步方法删除文件,使用callback形式返回结果
。
删除文件,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -828,7 +832,7 @@ unlink(path:string, callback:AsyncCallback<void>): void
...
@@ -828,7 +832,7 @@ unlink(path:string, callback:AsyncCallback<void>): void
**示例:**
**示例:**
```
js
```
js
fileio
.
unlink
(
path
,
function
(
err
)
{
fileio
.
unlink
(
path
,
function
(
err
)
{
console
.
info
(
"
remove file succe
ssfully
"
);
console
.
info
(
"
remove file succe
ed
"
);
});
});
```
```
...
@@ -861,7 +865,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
...
@@ -861,7 +865,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
encoding?: string;
encoding?: string;
}): Promise
<
number
>
}): Promise
<
number
>
以异步方法将数据写入文件,使用promise形式返回结果
。
将数据写入文件,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -875,13 +879,13 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
...
@@ -875,13 +879,13 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| --------------------- | -------- |
| --------------------- | -------- |
| Promise
<
number
>
| 实际写入的长度。 |
| Promise
<
number
>
|
Promise对象。返回
实际写入的长度。 |
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
fpath
,
0o100
|
0o2
,
0o666
);
let
fd
=
fileio
.
openSync
(
fpath
,
0o100
|
0o2
,
0o666
);
fileio
.
write
(
fd
,
"
hello, world
"
).
then
(
function
(
number
){
fileio
.
write
(
fd
,
"
hello, world
"
).
then
(
function
(
number
){
console
.
info
(
"
write data to file succe
ssfully
and size is:
"
+
number
);
console
.
info
(
"
write data to file succe
ed
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
);
});
});
...
@@ -897,7 +901,7 @@ write(fd: number, buffer: ArrayBuffer | string, options: {
...
@@ -897,7 +901,7 @@ write(fd: number, buffer: ArrayBuffer | string, options: {
encoding?: string;
encoding?: string;
}, callback: AsyncCallback
<
number
>
): void
}, callback: AsyncCallback
<
number
>
): void
以异步方法将数据写入文件,使用callback形式返回结果
。
将数据写入文件,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -914,7 +918,7 @@ write(fd: number, buffer: ArrayBuffer | string, options: {
...
@@ -914,7 +918,7 @@ write(fd: number, buffer: ArrayBuffer | string, options: {
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
(
"
write data to file succe
ssfully
and size is:
"
+
bytesWritten
);
console
.
info
(
"
write data to file succe
ed
and size is:
"
+
bytesWritten
);
}
}
});
});
```
```
...
@@ -956,7 +960,7 @@ writeSync(fd: number, buffer: ArrayBuffer | string, options?: {
...
@@ -956,7 +960,7 @@ writeSync(fd: number, buffer: ArrayBuffer | string, options?: {
hash(path: string, algorithm: string): Promise
<
string
>
hash(path: string, algorithm: string): Promise
<
string
>
以异步方法计算文件的哈希值,使用promise形式返回结果
。
计算文件的哈希值,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -969,12 +973,12 @@ hash(path: string, algorithm: string): Promise<string>
...
@@ -969,12 +973,12 @@ hash(path: string, algorithm: string): Promise<string>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| --------------------- | -------------------------- |
| --------------------- | -------------------------- |
| Promise
<
string
>
| 文件的哈希值。表示为十六进制数字串,所有字母均大写。 |
| Promise
<
string
>
|
Promise对象。返回
文件的哈希值。表示为十六进制数字串,所有字母均大写。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
hash
(
path
,
"
sha256
"
).
then
(
function
(
str
){
fileio
.
hash
(
path
,
"
sha256
"
).
then
(
function
(
str
){
console
.
info
(
"
calculate file hash succe
ssfully
:
"
+
str
);
console
.
info
(
"
calculate file hash succe
ed
:
"
+
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
);
});
});
...
@@ -985,7 +989,7 @@ hash(path: string, algorithm: string): Promise<string>
...
@@ -985,7 +989,7 @@ hash(path: string, algorithm: string): Promise<string>
hash(path: string, algorithm: string, callback: AsyncCallback
<
string
>
): void
hash(path: string, algorithm: string, callback: AsyncCallback
<
string
>
): void
以异步方法计算文件的哈希值,使用callback形式返回结果
。
计算文件的哈希值,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -994,13 +998,13 @@ hash(path: string, algorithm: string, callback: AsyncCallback<string>): vo
...
@@ -994,13 +998,13 @@ hash(path: string, algorithm: string, callback: AsyncCallback<string>): vo
| --------- | --------------------------- | ---- | ------------------------------------------------------------ |
| --------- | --------------------------- | ---- | ------------------------------------------------------------ |
| path | string | 是 | 待计算哈希值文件的应用沙箱路径。 |
| path | string | 是 | 待计算哈希值文件的应用沙箱路径。 |
| algorithm | string | 是 | 哈希计算采用的算法。可选
"md5"、"sha1"
或
"sha256"。建议采用安全强度更高的
"sha256"。 |
| algorithm | string | 是 | 哈希计算采用的算法。可选
"md5"、"sha1"
或
"sha256"。建议采用安全强度更高的
"sha256"。 |
| callback | AsyncCallback
<
string
>
| 是 | 异步计算文件哈希操之后的回调函数(其中给定文件哈希值表示为十六进制数字串,所有字母均大写)。 |
| callback | AsyncCallback
<
string
>
| 是 | 异步计算文件哈希操
作
之后的回调函数(其中给定文件哈希值表示为十六进制数字串,所有字母均大写)。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
hash
(
fpath
,
"
sha256
"
,
function
(
err
,
hashStr
)
{
fileio
.
hash
(
fpath
,
"
sha256
"
,
function
(
err
,
hashStr
)
{
if
(
hashStr
)
{
if
(
hashStr
)
{
console
.
info
(
"
calculate file hash succe
ssfully
:
"
+
hashStr
);
console
.
info
(
"
calculate file hash succe
ed
:
"
+
hashStr
);
}
}
});
});
```
```
...
@@ -1010,25 +1014,25 @@ hash(path: string, algorithm: string, callback: AsyncCallback<string>): vo
...
@@ -1010,25 +1014,25 @@ hash(path: string, algorithm: string, callback: AsyncCallback<string>): vo
chmod(path: string, mode: number):Promise
<
void
>
chmod(path: string, mode: number):Promise
<
void
>
以异步方法基于文件路径改变文件权限,使用promise形式返回结果
。
改变文件权限,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | 是 |
待改变文件权限
的应用沙箱路径。 |
| path | string | 是 |
所需变更权限的文件
的应用沙箱路径。 |
| mode | number | 是 | 改变文件权限,可给定如下权限,以按位或的方式追加权限。
<br/>
-
0o700:所有者具有读、写及可执行权限。
<br/>
-
0o400:所有者具有读权限。
<br/>
-
0o200:所有者具有写权限。
<br/>
-
0o100:所有者具有可执行权限。
<br/>
-
0o070:所有用户组具有读、写及可执行权限。
<br/>
-
0o040:所有用户组具有读权限。
<br/>
-
0o020:所有用户组具有写权限。
<br/>
-
0o010:所有用户组具有可执行权限。
<br/>
-
0o007:其余用户具有读、写及可执行权限。
<br/>
-
0o004:其余用户具有读权限。
<br/>
-
0o002:其余用户具有写权限。
<br/>
-
0o001:其余用户具有可执行权限。 |
| mode | number | 是 | 改变文件权限,可给定如下权限,以按位或的方式追加权限。
<br/>
-
0o700:所有者具有读、写及可执行权限。
<br/>
-
0o400:所有者具有读权限。
<br/>
-
0o200:所有者具有写权限。
<br/>
-
0o100:所有者具有可执行权限。
<br/>
-
0o070:所有用户组具有读、写及可执行权限。
<br/>
-
0o040:所有用户组具有读权限。
<br/>
-
0o020:所有用户组具有写权限。
<br/>
-
0o010:所有用户组具有可执行权限。
<br/>
-
0o007:其余用户具有读、写及可执行权限。
<br/>
-
0o004:其余用户具有读权限。
<br/>
-
0o002:其余用户具有写权限。
<br/>
-
0o001:其余用户具有可执行权限。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果。本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
chmod
(
path
,
mode
).
then
(
function
()
{
fileio
.
chmod
(
path
,
mode
).
then
(
function
()
{
console
.
info
(
"
chmod succe
ssfully
"
);
console
.
info
(
"
chmod succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
chmod failed with error:
"
+
err
);
console
.
info
(
"
chmod failed with error:
"
+
err
);
});
});
...
@@ -1039,14 +1043,14 @@ chmod(path: string, mode: number):Promise<void>
...
@@ -1039,14 +1043,14 @@ chmod(path: string, mode: number):Promise<void>
chmod(path: string, mode: number, callback: AsyncCallback
<
void
>
): void
chmod(path: string, mode: number, callback: AsyncCallback
<
void
>
): void
以异步方法基于文件路径改变文件权限,使用callback形式返回结果
。
改变文件权限,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | 是 |
待改变文件权限
的应用沙箱路径。 |
| path | string | 是 |
所需变更权限的文件
的应用沙箱路径。 |
| mode | number | 是 | 改变文件权限,可给定如下权限,以按位或的方式追加权限。
<br/>
-
0o700:所有者具有读、写及可执行权限。
<br/>
-
0o400:所有者具有读权限。
<br/>
-
0o200:所有者具有写权限。
<br/>
-
0o100:所有者具有可执行权限。
<br/>
-
0o070:所有用户组具有读、写及可执行权限。
<br/>
-
0o040:所有用户组具有读权限。
<br/>
-
0o020:所有用户组具有写权限。
<br/>
-
0o010:所有用户组具有可执行权限。
<br/>
-
0o007:其余用户具有读、写及可执行权限。
<br/>
-
0o004:其余用户具有读权限。
<br/>
-
0o002:其余用户具有写权限。
<br/>
-
0o001:其余用户具有可执行权限。 |
| mode | number | 是 | 改变文件权限,可给定如下权限,以按位或的方式追加权限。
<br/>
-
0o700:所有者具有读、写及可执行权限。
<br/>
-
0o400:所有者具有读权限。
<br/>
-
0o200:所有者具有写权限。
<br/>
-
0o100:所有者具有可执行权限。
<br/>
-
0o070:所有用户组具有读、写及可执行权限。
<br/>
-
0o040:所有用户组具有读权限。
<br/>
-
0o020:所有用户组具有写权限。
<br/>
-
0o010:所有用户组具有可执行权限。
<br/>
-
0o007:其余用户具有读、写及可执行权限。
<br/>
-
0o004:其余用户具有读权限。
<br/>
-
0o002:其余用户具有写权限。
<br/>
-
0o001:其余用户具有可执行权限。 |
| callback | AsyncCallback
<
void
>
| 是 | 异步改变文件权限之后的回调。 |
| callback | AsyncCallback
<
void
>
| 是 | 异步改变文件权限之后的回调。 |
...
@@ -1062,14 +1066,14 @@ chmod(path: string, mode: number, callback: AsyncCallback<void>): void
...
@@ -1062,14 +1066,14 @@ chmod(path: string, mode: number, callback: AsyncCallback<void>): void
chmodSync(path: string, mode: number): void
chmodSync(path: string, mode: number): void
以同步方法
基于文件路径
改变文件权限。
以同步方法改变文件权限。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | 是 |
待改变文件权限
的应用沙箱路径。 |
| path | string | 是 |
所需变更权限的文件
的应用沙箱路径。 |
| mode | number | 是 | 改变文件权限,可给定如下权限,以按位或的方式追加权限。
<br/>
-
0o700:所有者具有读、写及可执行权限。
<br/>
-
0o400:所有者具有读权限。
<br/>
-
0o200:所有者具有写权限。
<br/>
-
0o100:所有者具有可执行权限。
<br/>
-
0o070:所有用户组具有读、写及可执行权限。
<br/>
-
0o040:所有用户组具有读权限。
<br/>
-
0o020:所有用户组具有写权限。
<br/>
-
0o010:所有用户组具有可执行权限。
<br/>
-
0o007:其余用户具有读、写及可执行权限。
<br/>
-
0o004:其余用户具有读权限。
<br/>
-
0o002:其余用户具有写权限。
<br/>
-
0o001:其余用户具有可执行权限。 |
| mode | number | 是 | 改变文件权限,可给定如下权限,以按位或的方式追加权限。
<br/>
-
0o700:所有者具有读、写及可执行权限。
<br/>
-
0o400:所有者具有读权限。
<br/>
-
0o200:所有者具有写权限。
<br/>
-
0o100:所有者具有可执行权限。
<br/>
-
0o070:所有用户组具有读、写及可执行权限。
<br/>
-
0o040:所有用户组具有读权限。
<br/>
-
0o020:所有用户组具有写权限。
<br/>
-
0o010:所有用户组具有可执行权限。
<br/>
-
0o007:其余用户具有读、写及可执行权限。
<br/>
-
0o004:其余用户具有读权限。
<br/>
-
0o002:其余用户具有写权限。
<br/>
-
0o001:其余用户具有可执行权限。 |
**示例:**
**示例:**
...
@@ -1082,24 +1086,24 @@ chmodSync(path: string, mode: number): void
...
@@ -1082,24 +1086,24 @@ chmodSync(path: string, mode: number): void
fstat(fd: number): Promise
<
Stat
>
fstat(fd: number): Promise
<
Stat
>
以异步方法基于文件描述符获取文件状态信息,使用promise形式返回结果
。
基于文件描述符获取文件状态信息,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | ------------ |
| ---- | ------ | ---- | ------------ |
| fd | number | 是 | 待获取文件的文件描述符。 |
| fd | number | 是 | 待获取文件
状态
的文件描述符。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ---------------------------- | ---------- |
| ---------------------------- | ---------- |
| Promise
<
[Stat](#stat)
>
|
表示文件
的具体信息。 |
| Promise
<
[Stat](#stat)
>
|
Promise对象。返回表示文件状态
的具体信息。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
fstat
(
fd
).
then
(
function
(
stat
){
fileio
.
fstat
(
fd
).
then
(
function
(
stat
){
console
.
info
(
"
fstat succe
ssfully
:
"
+
JSON
.
stringify
(
stat
));
console
.
info
(
"
fstat succe
ed
:
"
+
JSON
.
stringify
(
stat
));
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
fstat failed with error:
"
+
err
);
console
.
info
(
"
fstat failed with error:
"
+
err
);
});
});
...
@@ -1110,14 +1114,14 @@ fstat(fd: number): Promise<Stat>
...
@@ -1110,14 +1114,14 @@ fstat(fd: number): Promise<Stat>
fstat(fd: number, callback: AsyncCallback
<
Stat
>
): void
fstat(fd: number, callback: AsyncCallback
<
Stat
>
): void
以异步方法基于文件描述符获取文件状态信息,使用callback形式返回结果
。
基于文件描述符获取文件状态信息,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------- | ---- | ---------------- |
| -------- | ---------------------------------- | ---- | ---------------- |
| fd | number | 是 | 待获取文件的文件描述符。 |
| fd | number | 是 | 待获取文件
状态
的文件描述符。 |
| callback | AsyncCallback
<
[Stat](#stat)
>
| 是 | 异步获取文件状态信息之后的回调。 |
| callback | AsyncCallback
<
[Stat](#stat)
>
| 是 | 异步获取文件状态信息之后的回调。 |
**示例:**
**示例:**
...
@@ -1140,12 +1144,12 @@ fstatSync(fd: number): Stat
...
@@ -1140,12 +1144,12 @@ fstatSync(fd: number): Stat
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | ------------ |
| ---- | ------ | ---- | ------------ |
| fd | number | 是 | 待获取文件的文件描述符。 |
| fd | number | 是 | 待获取文件
状态
的文件描述符。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------- | ---------- |
| ------------- | ---------- |
|
[
Stat
](
#stat
)
| 表示文件的具体信息。 |
|
[
Stat
](
#stat
)
| 表示文件
状态
的具体信息。 |
**示例:**
**示例:**
```
js
```
js
...
@@ -1158,7 +1162,7 @@ fstatSync(fd: number): Stat
...
@@ -1158,7 +1162,7 @@ fstatSync(fd: number): Stat
ftruncate(fd: number, len?: number): Promise
<
void
>
ftruncate(fd: number, len?: number): Promise
<
void
>
以异步方法基于文件描述符截断文件,使用promise形式返回结果
。
基于文件描述符截断文件,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1166,18 +1170,18 @@ ftruncate(fd: number, len?: number): Promise<void>
...
@@ -1166,18 +1170,18 @@ ftruncate(fd: number, len?: number): Promise<void>
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | ---------------- |
| ---- | ------ | ---- | ---------------- |
| fd | number | 是 | 待截断文件的文件描述符。 |
| fd | number | 是 | 待截断文件的文件描述符。 |
| len | number |
是
| 文件截断后的长度,以字节为单位。 |
| len | number |
否
| 文件截断后的长度,以字节为单位。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果。本调用将返回空值。
|
| Promise
<
void
>
| Promise
对象。无返回值。
|
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
let
fd
=
fileio
.
openSync
(
path
);
fileio
.
ftruncate
(
fd
,
5
).
then
(
function
(
err
)
{
fileio
.
ftruncate
(
fd
,
5
).
then
(
function
(
err
)
{
console
.
info
(
"
truncate file succe
ssfully
"
);
console
.
info
(
"
truncate file succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
truncate file failed with error:
"
+
err
);
console
.
info
(
"
truncate file failed with error:
"
+
err
);
});
});
...
@@ -1188,7 +1192,7 @@ ftruncate(fd: number, len?: number): Promise<void>
...
@@ -1188,7 +1192,7 @@ ftruncate(fd: number, len?: number): Promise<void>
ftruncate(fd: number, len: number, callback:AsyncCallback
<
void
>
): void
ftruncate(fd: number, len: number, callback:AsyncCallback
<
void
>
): void
以异步方法基于文件描述符截断文件,使用callback形式返回结果
。
基于文件描述符截断文件,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1231,7 +1235,7 @@ ftruncateSync(fd: number, len?: number): void
...
@@ -1231,7 +1235,7 @@ ftruncateSync(fd: number, len?: number): void
truncate(path: string, len?: number): Promise
<
void
>
truncate(path: string, len?: number): Promise
<
void
>
以异步方法基于文件路径截断文件,使用promise形式返回结果
。
基于文件路径截断文件,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1239,17 +1243,17 @@ truncate(path: string, len?: number): Promise<void>
...
@@ -1239,17 +1243,17 @@ truncate(path: string, len?: number): Promise<void>
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------------------- |
| ------ | ------ | ---- | -------------------------------- |
| path | string | 是 | 待截断文件的应用沙箱路径。 |
| path | string | 是 | 待截断文件的应用沙箱路径。 |
| len | number |
是
| 文件截断后的长度,以字节为单位。 |
| len | number |
否
| 文件截断后的长度,以字节为单位。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果。本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
truncate
(
path
,
len
).
then
(
function
(){
fileio
.
truncate
(
path
,
len
).
then
(
function
(){
console
.
info
(
"
truncate file succe
ssfully
"
);
console
.
info
(
"
truncate file succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
truncate file failed with error:
"
+
err
);
console
.
info
(
"
truncate file failed with error:
"
+
err
);
});
});
...
@@ -1260,7 +1264,7 @@ truncate(path: string, len?: number): Promise<void>
...
@@ -1260,7 +1264,7 @@ truncate(path: string, len?: number): Promise<void>
truncate(path: string, len: number, callback:AsyncCallback
<
void
>
): void
truncate(path: string, len: number, callback:AsyncCallback
<
void
>
): void
以异步方法基于文件路径截断文件,使用callback形式返回结果
。
基于文件路径截断文件,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1307,7 +1311,7 @@ readText(filePath: string, options?: {
...
@@ -1307,7 +1311,7 @@ readText(filePath: string, options?: {
encoding?: string;
encoding?: string;
}): Promise
<
string
>
}): Promise
<
string
>
以异步方法基于文本方式读取文件(即直接读取文件的文本内容),使用promise形式返回结果
。
基于文本方式读取文件(即直接读取文件的文本内容),使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1320,12 +1324,12 @@ readText(filePath: string, options?: {
...
@@ -1320,12 +1324,12 @@ readText(filePath: string, options?: {
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| --------------------- | ---------- |
| --------------------- | ---------- |
| Promise
<
string
>
| 返回读取文件的内容。 |
| Promise
<
string
>
|
Promise对象。
返回读取文件的内容。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
readText
(
path
).
then
(
function
(
str
)
{
fileio
.
readText
(
path
).
then
(
function
(
str
)
{
console
.
info
(
"
readText succe
ssfully
:
"
+
str
);
console
.
info
(
"
readText succe
ed
:
"
+
str
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
readText failed with error:
"
+
err
);
console
.
info
(
"
readText failed with error:
"
+
err
);
});
});
...
@@ -1340,7 +1344,7 @@ readText(filePath: string, options: {
...
@@ -1340,7 +1344,7 @@ readText(filePath: string, options: {
encoding?: string;
encoding?: string;
}, callback: AsyncCallback
<
string
>
): void
}, callback: AsyncCallback
<
string
>
): void
以异步方法基于文本方式读取文件(即直接读取文件的文本内容),使用callback形式返回结果
。
基于文本方式读取文件(即直接读取文件的文本内容),使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1392,24 +1396,24 @@ readTextSync(filePath: string, options?: {
...
@@ -1392,24 +1396,24 @@ readTextSync(filePath: string, options?: {
lstat(path: string): Promise
<
Stat
>
lstat(path: string): Promise
<
Stat
>
以异步方法获取链接状态信息,使用promise形式返回结果
。
获取链接信息,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------------------------- |
| ------ | ------ | ---- | -------------------------------------- |
| path | string | 是 | 目标文件的应用沙箱路径,指向链接
状态
。 |
| path | string | 是 | 目标文件的应用沙箱路径,指向链接。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ---------------------------- | ---------- |
| ---------------------------- | ---------- |
| Promise
<
[Stat](#stat)
>
|
表示文件
的具体信息。 |
| Promise
<
[Stat](#stat)
>
|
Promise对象。返回表示文件状态
的具体信息。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
lstat
(
path
).
then
(
function
(
stat
){
fileio
.
lstat
(
path
).
then
(
function
(
stat
){
console
.
info
(
"
get link status succe
ssfully
:
"
+
number
);
console
.
info
(
"
get link status succe
ed
:
"
+
number
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
get link status failed with error:
"
+
err
);
console
.
info
(
"
get link status failed with error:
"
+
err
);
});
});
...
@@ -1420,15 +1424,15 @@ lstat(path: string): Promise<Stat>
...
@@ -1420,15 +1424,15 @@ lstat(path: string): Promise<Stat>
lstat(path:string, callback:AsyncCallback
<
Stat
>
): void
lstat(path:string, callback:AsyncCallback
<
Stat
>
): void
以异步方法获取链接状态信息,使用callback形式返回结果
。
获取链接信息,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------- | ---- | -------------------------------------- |
| -------- | ---------------------------------- | ---- | -------------------------------------- |
| path | string | 是 | 目标文件的应用沙箱路径,指向链接
状态
。 |
| path | string | 是 | 目标文件的应用沙箱路径,指向链接。 |
| callback | AsyncCallback
<
[Stat](#stat)
>
| 是 | 异步获取链接
状态
信息之后的回调。 |
| callback | AsyncCallback
<
[Stat](#stat)
>
| 是 | 异步获取链接信息之后的回调。 |
**示例:**
**示例:**
```
js
```
js
...
@@ -1442,14 +1446,14 @@ lstat(path:string, callback:AsyncCallback<Stat>): void
...
@@ -1442,14 +1446,14 @@ lstat(path:string, callback:AsyncCallback<Stat>): void
lstatSync(path:string): Stat
lstatSync(path:string): Stat
以同步方法获取链接
状态
信息。
以同步方法获取链接信息。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------------------------- |
| ------ | ------ | ---- | -------------------------------------- |
| path | string | 是 | 目标文件的应用沙箱路径,指向链接
状态
。 |
| path | string | 是 | 目标文件的应用沙箱路径,指向链接。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
...
@@ -1470,7 +1474,7 @@ read(buffer: ArrayBuffer, options?: {
...
@@ -1470,7 +1474,7 @@ read(buffer: ArrayBuffer, options?: {
length?: number;
length?: number;
}): Promise
<
ReadOut
>
}): Promise
<
ReadOut
>
以异步方法从文件读取数据,使用promise形式返回结果
。
从文件读取数据,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1483,12 +1487,12 @@ read(buffer: ArrayBuffer, options?: {
...
@@ -1483,12 +1487,12 @@ read(buffer: ArrayBuffer, options?: {
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ---------------------------------- | ------ |
| ---------------------------------- | ------ |
| Promise
<
[ReadOut](#readout)
>
| 读取的结果。 |
| Promise
<
[ReadOut](#readout)
>
|
Promise对象。返回
读取的结果。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
read
(
new
ArrayBuffer
(
4096
)).
then
(
function
(
readout
){
fileio
.
read
(
new
ArrayBuffer
(
4096
)).
then
(
function
(
readout
){
console
.
info
(
"
read file data succe
ssfully
"
);
console
.
info
(
"
read file data succe
ed
"
);
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 file data failed with error:
"
+
err
);
console
.
info
(
"
read file data failed with error:
"
+
err
);
...
@@ -1504,7 +1508,7 @@ read(buffer: ArrayBuffer, options: {
...
@@ -1504,7 +1508,7 @@ read(buffer: ArrayBuffer, options: {
length?: number;
length?: number;
}, callback: AsyncCallback
<
ReadOut
>
): void
}, callback: AsyncCallback
<
ReadOut
>
): void
异步方法从文件读取数据,使用callback形式返回结果
。
从文件读取数据,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1520,7 +1524,7 @@ read(buffer: ArrayBuffer, options: {
...
@@ -1520,7 +1524,7 @@ read(buffer: ArrayBuffer, options: {
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 succe
ssfully
"
);
console
.
info
(
"
read file data succe
ed
"
);
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
}
}
});
});
...
@@ -1531,7 +1535,7 @@ read(buffer: ArrayBuffer, options: {
...
@@ -1531,7 +1535,7 @@ read(buffer: ArrayBuffer, options: {
rename(oldPath: string, newPath: string): Promise
<
void
>
rename(oldPath: string, newPath: string): Promise
<
void
>
以异步方法重命名文件,使用promise形式返回结果
。
重命名文件,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1544,12 +1548,12 @@ rename(oldPath: string, newPath: string): Promise<void>
...
@@ -1544,12 +1548,12 @@ rename(oldPath: string, newPath: string): Promise<void>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果。本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
rename
(
oldPath
,
newPath
).
then
(
function
()
{
fileio
.
rename
(
oldPath
,
newPath
).
then
(
function
()
{
console
.
info
(
"
rename succe
ssfully
"
);
console
.
info
(
"
rename succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
rename failed with error:
"
+
err
);
console
.
info
(
"
rename failed with error:
"
+
err
);
});
});
...
@@ -1560,7 +1564,7 @@ rename(oldPath: string, newPath: string): Promise<void>
...
@@ -1560,7 +1564,7 @@ rename(oldPath: string, newPath: string): Promise<void>
rename(oldPath: string, newPath: string, callback: AsyncCallback
<
void
>
): void
rename(oldPath: string, newPath: string, callback: AsyncCallback
<
void
>
): void
以异步方法重命名文件,使用callback形式返回结果
。
重命名文件,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1602,7 +1606,7 @@ renameSync(oldPath: string, newPath: string): void
...
@@ -1602,7 +1606,7 @@ renameSync(oldPath: string, newPath: string): void
fsync(fd: number): Promise
<
void
>
fsync(fd: number): Promise
<
void
>
以异步方法同步文件数据,使用promise形式返回结果
。
同步文件数据,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1614,12 +1618,12 @@ fsync(fd: number): Promise<void>
...
@@ -1614,12 +1618,12 @@ fsync(fd: number): Promise<void>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果。本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
fsync
(
fd
).
then
(
function
(){
fileio
.
fsync
(
fd
).
then
(
function
(){
console
.
info
(
"
sync data succe
ssfully
"
);
console
.
info
(
"
sync data succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
sync data failed with error:
"
+
err
);
console
.
info
(
"
sync data failed with error:
"
+
err
);
});
});
...
@@ -1630,7 +1634,7 @@ fsync(fd: number): Promise<void>
...
@@ -1630,7 +1634,7 @@ fsync(fd: number): Promise<void>
fsync(fd: number, callback: AsyncCallback
<
void
>
): void
fsync(fd: number, callback: AsyncCallback
<
void
>
): void
以异步方法同步文件数据,使用callback形式返回结果
。
同步文件数据,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1671,7 +1675,7 @@ fsyncSync(fd: number): void
...
@@ -1671,7 +1675,7 @@ fsyncSync(fd: number): void
fdatasync(fd: number): Promise
<
void
>
fdatasync(fd: number): Promise
<
void
>
以异步方法实现文件内容数据同步,使用promise形式返回结果
。
实现文件内容数据同步,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1683,12 +1687,12 @@ fdatasync(fd: number): Promise<void>
...
@@ -1683,12 +1687,12 @@ fdatasync(fd: number): Promise<void>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果,本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
fdatasync
(
fd
).
then
(
function
(
err
)
{
fileio
.
fdatasync
(
fd
).
then
(
function
(
err
)
{
console
.
info
(
"
sync data succe
ssfully
"
);
console
.
info
(
"
sync data succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
sync data failed with error:
"
+
err
);
console
.
info
(
"
sync data failed with error:
"
+
err
);
});
});
...
@@ -1699,7 +1703,7 @@ fdatasync(fd: number): Promise<void>
...
@@ -1699,7 +1703,7 @@ fdatasync(fd: number): Promise<void>
fdatasync(fd: number, callback:AsyncCallback
<
void
>
): void
fdatasync(fd: number, callback:AsyncCallback
<
void
>
): void
以异步方法实现文件内容数据同步,使用callback形式返回结果
。
实现文件内容数据同步,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1740,7 +1744,7 @@ fdatasyncSync(fd: number): void
...
@@ -1740,7 +1744,7 @@ fdatasyncSync(fd: number): void
symlink(target: string, srcPath: string): Promise
<
void
>
symlink(target: string, srcPath: string): Promise
<
void
>
以异步方法基于文件路径创建符号链接,使用promise形式返回结果
。
基于文件路径创建符号链接,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1753,12 +1757,12 @@ symlink(target: string, srcPath: string): Promise<void>
...
@@ -1753,12 +1757,12 @@ symlink(target: string, srcPath: string): Promise<void>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果,本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
symlink
(
target
,
srcPath
).
then
(
function
()
{
fileio
.
symlink
(
target
,
srcPath
).
then
(
function
()
{
console
.
info
(
"
symlink succe
ssfully
"
);
console
.
info
(
"
symlink succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
symlink failed with error:
"
+
err
);
console
.
info
(
"
symlink failed with error:
"
+
err
);
});
});
...
@@ -1769,7 +1773,7 @@ symlink(target: string, srcPath: string): Promise<void>
...
@@ -1769,7 +1773,7 @@ symlink(target: string, srcPath: string): Promise<void>
symlink(target: string, srcPath: string, callback: AsyncCallback
<
void
>
): void
symlink(target: string, srcPath: string, callback: AsyncCallback
<
void
>
): void
以异步方法基于文件路径创建符号链接,使用callback形式返回结果
。
基于文件路径创建符号链接,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1812,7 +1816,7 @@ symlinkSync(target: string, srcPath: string): void
...
@@ -1812,7 +1816,7 @@ symlinkSync(target: string, srcPath: string): void
chown(path: string, uid: number, gid: number): Promise
<
void
>
chown(path: string, uid: number, gid: number): Promise
<
void
>
以异步的方法基于文件路径改变文件所有者,使用promise形式返回结果
。
基于文件路径改变文件所有者,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1826,13 +1830,13 @@ chown(path: string, uid: number, gid: number): Promise<void>
...
@@ -1826,13 +1830,13 @@ chown(path: string, uid: number, gid: number): Promise<void>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果,本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
let
stat
=
fileio
.
statSync
(
path
);
let
stat
=
fileio
.
statSync
(
path
);
fileio
.
chown
(
path
,
stat
.
uid
,
stat
.
gid
).
then
(
function
(){
fileio
.
chown
(
path
,
stat
.
uid
,
stat
.
gid
).
then
(
function
(){
console
.
info
(
"
chown succe
ssfully
"
);
console
.
info
(
"
chown succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
chown failed with error:
"
+
err
);
console
.
info
(
"
chown failed with error:
"
+
err
);
});
});
...
@@ -1843,7 +1847,7 @@ chown(path: string, uid: number, gid: number): Promise<void>
...
@@ -1843,7 +1847,7 @@ chown(path: string, uid: number, gid: number): Promise<void>
chown(path: string, uid: number, gid: number, callback: AsyncCallback
<
void
>
): void
chown(path: string, uid: number, gid: number, callback: AsyncCallback
<
void
>
): void
以异步的方法基于文件路径改变文件所有者,使用callback形式返回结果
。
基于文件路径改变文件所有者,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1890,7 +1894,7 @@ chownSync(path: string, uid: number, gid: number): void
...
@@ -1890,7 +1894,7 @@ chownSync(path: string, uid: number, gid: number): void
mkdtemp(prefix: string): Promise
<
string
>
mkdtemp(prefix: string): Promise
<
string
>
以异步的方法创建临时目录,使用promise形式返回结果
。
创建临时目录,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1902,12 +1906,12 @@ mkdtemp(prefix: string): Promise<string>
...
@@ -1902,12 +1906,12 @@ mkdtemp(prefix: string): Promise<string>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| --------------------- | ---------- |
| --------------------- | ---------- |
| Promise
<
string
>
| 生成的唯一目录路径。 |
| Promise
<
string
>
|
Promise对象。返回
生成的唯一目录路径。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
mkdtemp
(
path
+
"
XXXX
"
).
then
(
function
(
path
){
fileio
.
mkdtemp
(
path
+
"
XXXX
"
).
then
(
function
(
path
){
console
.
info
(
"
mkdtemp succe
ssfully
:
"
+
path
);
console
.
info
(
"
mkdtemp succe
ed
:
"
+
path
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
mkdtemp failed with error:
"
+
err
);
console
.
info
(
"
mkdtemp failed with error:
"
+
err
);
});
});
...
@@ -1918,7 +1922,7 @@ mkdtemp(prefix: string): Promise<string>
...
@@ -1918,7 +1922,7 @@ mkdtemp(prefix: string): Promise<string>
mkdtemp(prefix: string, callback: AsyncCallback
<
string
>
): void
mkdtemp(prefix: string, callback: AsyncCallback
<
string
>
): void
以异步的方法创建临时目录,使用callback形式返回结果
。
创建临时目录,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1964,7 +1968,7 @@ mkdtempSync(prefix: string): string
...
@@ -1964,7 +1968,7 @@ mkdtempSync(prefix: string): string
fchmod(fd: number, mode: number): Promise
<
void
>
fchmod(fd: number, mode: number): Promise
<
void
>
以异步方法基于文件描述符改变文件权限,使用promise形式返回结果
。
基于文件描述符改变文件权限,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -1977,12 +1981,12 @@ fchmod(fd: number, mode: number): Promise<void>
...
@@ -1977,12 +1981,12 @@ fchmod(fd: number, mode: number): Promise<void>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果,本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
fchmod
(
fd
,
mode
).
then
(
function
()
{
fileio
.
fchmod
(
fd
,
mode
).
then
(
function
()
{
console
.
info
(
"
chmod succe
ssfully
"
);
console
.
info
(
"
chmod succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
chmod failed with error:
"
+
err
);
console
.
info
(
"
chmod failed with error:
"
+
err
);
});
});
...
@@ -1993,7 +1997,7 @@ fchmod(fd: number, mode: number): Promise<void>
...
@@ -1993,7 +1997,7 @@ fchmod(fd: number, mode: number): Promise<void>
fchmod(fd: number, mode: number, callback: AsyncCallback
<
void
>
): void
fchmod(fd: number, mode: number, callback: AsyncCallback
<
void
>
): void
以异步方法基于文件描述符改变文件权限,使用callback形式返回结果
。
基于文件描述符改变文件权限,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2036,7 +2040,7 @@ fchmodSync(fd: number, mode: number): void
...
@@ -2036,7 +2040,7 @@ fchmodSync(fd: number, mode: number): void
createStream(path: string, mode: string): Promise
<
Stream
>
createStream(path: string, mode: string): Promise
<
Stream
>
以异步方法基于文件路径打开文件流,使用promise形式返回结果
。
基于文件路径打开文件流,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2049,12 +2053,12 @@ createStream(path: string, mode: string): Promise<Stream>
...
@@ -2049,12 +2053,12 @@ createStream(path: string, mode: string): Promise<Stream>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| --------------------------------- | --------- |
| --------------------------------- | --------- |
| Promise
<
[Stream](#stream7)
>
| 返回文件流的结果。 |
| Promise
<
[Stream](#stream7)
>
|
Promise对象。
返回文件流的结果。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
createStream
(
path
,
"
r+
"
).
then
(
function
(
stream
){
fileio
.
createStream
(
path
,
"
r+
"
).
then
(
function
(
stream
){
console
.
info
(
"
createStream succe
ssfully
"
);
console
.
info
(
"
createStream succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
createStream failed with error:
"
+
err
);
console
.
info
(
"
createStream failed with error:
"
+
err
);
});
});
...
@@ -2065,7 +2069,7 @@ createStream(path: string, mode: string): Promise<Stream>
...
@@ -2065,7 +2069,7 @@ createStream(path: string, mode: string): Promise<Stream>
createStream(path: string, mode: string, callback: AsyncCallback
<
Stream
>
): void
createStream(path: string, mode: string, callback: AsyncCallback
<
Stream
>
): void
以异步方法基于文件路径打开文件流,使用callback形式返回结果
。
基于文件路径打开文件流,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2113,7 +2117,7 @@ createStreamSync(path: string, mode: string): Stream
...
@@ -2113,7 +2117,7 @@ createStreamSync(path: string, mode: string): Stream
fdopenStream(fd: number, mode: string): Promise
<
Stream
>
fdopenStream(fd: number, mode: string): Promise
<
Stream
>
以异步方法基于文件描述符打开文件流,使用promise形式返回结果
。
基于文件描述符打开文件流,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2126,12 +2130,12 @@ fdopenStream(fd: number, mode: string): Promise<Stream>
...
@@ -2126,12 +2130,12 @@ fdopenStream(fd: number, mode: string): Promise<Stream>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| --------------------------------- | --------- |
| --------------------------------- | --------- |
| Promise
<
[Stream](#stream7)
>
| 返回文件流的结果。 |
| Promise
<
[Stream](#stream7)
>
|
Promise对象。
返回文件流的结果。 |
**示例:**
**示例:**
```
js
```
js
fileio
.
fdopenStream
(
fd
,
mode
).
then
(
function
(
stream
){
fileio
.
fdopenStream
(
fd
,
mode
).
then
(
function
(
stream
){
console
.
info
(
"
openStream succe
ssfully
"
);
console
.
info
(
"
openStream succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
openStream failed with error:
"
+
err
);
console
.
info
(
"
openStream failed with error:
"
+
err
);
});
});
...
@@ -2142,7 +2146,7 @@ fdopenStream(fd: number, mode: string): Promise<Stream>
...
@@ -2142,7 +2146,7 @@ fdopenStream(fd: number, mode: string): Promise<Stream>
fdopenStream(fd: number, mode: string, callback: AsyncCallback
<
Stream
>
): void
fdopenStream(fd: number, mode: string, callback: AsyncCallback
<
Stream
>
): void
以异步方法基于文件描述符打开文件流,使用callback形式返回结果
。
基于文件描述符打开文件流,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2190,7 +2194,7 @@ fdopenStreamSync(fd: number, mode: string): Stream
...
@@ -2190,7 +2194,7 @@ fdopenStreamSync(fd: number, mode: string): Stream
fchown(fd: number, uid: number, gid: number): Promise
<
void
>
fchown(fd: number, uid: number, gid: number): Promise
<
void
>
以异步方法基于文件描述符改变文件所有者,使用promise形式返回结果
。
基于文件描述符改变文件所有者,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2204,13 +2208,13 @@ fchown(fd: number, uid: number, gid: number): Promise<void>
...
@@ -2204,13 +2208,13 @@ fchown(fd: number, uid: number, gid: number): Promise<void>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果。本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
let
stat
=
fileio
.
statSync
(
path
);
let
stat
=
fileio
.
statSync
(
path
);
fileio
.
fchown
(
fd
,
stat
.
uid
,
stat
.
gid
).
then
(
function
()
{
fileio
.
fchown
(
fd
,
stat
.
uid
,
stat
.
gid
).
then
(
function
()
{
console
.
info
(
"
chown succe
ssfully
"
);
console
.
info
(
"
chown succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
chown failed with error:
"
+
err
);
console
.
info
(
"
chown failed with error:
"
+
err
);
});
});
...
@@ -2221,7 +2225,7 @@ fchown(fd: number, uid: number, gid: number): Promise<void>
...
@@ -2221,7 +2225,7 @@ fchown(fd: number, uid: number, gid: number): Promise<void>
fchown(fd: number, uid: number, gid: number, callback: AsyncCallback
<
void
>
): void
fchown(fd: number, uid: number, gid: number, callback: AsyncCallback
<
void
>
): void
以异步方法基于文件描述符改变文件所有者,使用callback形式返回结果
。
基于文件描述符改变文件所有者,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2268,7 +2272,7 @@ fchownSync(fd: number, uid: number, gid: number): void
...
@@ -2268,7 +2272,7 @@ fchownSync(fd: number, uid: number, gid: number): void
lchown(path: string, uid: number, gid: number): Promise
<
void
>
lchown(path: string, uid: number, gid: number): Promise
<
void
>
以异步方法基于文件路径改变文件所有者,更改符号链接本身的所有者,而不是符号链接所指向的实际文件,使用promise形式返回结果
。
基于文件路径改变文件所有者,更改符号链接本身的所有者,而不是符号链接所指向的实际文件,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2282,13 +2286,13 @@ lchown(path: string, uid: number, gid: number): Promise<void>
...
@@ -2282,13 +2286,13 @@ lchown(path: string, uid: number, gid: number): Promise<void>
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果。本调用将返回空
值。 |
| Promise
<
void
>
| Promise
对象。无返回
值。 |
**示例:**
**示例:**
```
js
```
js
let
stat
=
fileio
.
statSync
(
path
);
let
stat
=
fileio
.
statSync
(
path
);
fileio
.
lchown
(
path
,
stat
.
uid
,
stat
.
gid
).
then
(
function
()
{
fileio
.
lchown
(
path
,
stat
.
uid
,
stat
.
gid
).
then
(
function
()
{
console
.
info
(
"
chown succe
ssfully
"
);
console
.
info
(
"
chown succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
chown failed with error:
"
+
err
);
console
.
info
(
"
chown failed with error:
"
+
err
);
});
});
...
@@ -2299,7 +2303,7 @@ lchown(path: string, uid: number, gid: number): Promise<void>
...
@@ -2299,7 +2303,7 @@ lchown(path: string, uid: number, gid: number): Promise<void>
lchown(path: string, uid: number, gid: number, callback: AsyncCallback
<
void
>
): void
lchown(path: string, uid: number, gid: number, callback: AsyncCallback
<
void
>
): void
以异步方法基于文件路径改变文件所有者,更改符号链接本身的所有者,而不是更改符号链接所指向的实际文件,使用callback形式返回结果
。
基于文件路径改变文件所有者,更改符号链接本身的所有者,而不是更改符号链接所指向的实际文件,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2346,7 +2350,7 @@ lchownSync(path: string, uid: number, gid: number): void
...
@@ -2346,7 +2350,7 @@ lchownSync(path: string, uid: number, gid: number): void
createWatcher(filename: string, events: number, callback: AsyncCallback
<
number
>
): Watcher
createWatcher(filename: string, events: number, callback: AsyncCallback
<
number
>
): Watcher
以异步方法监听文件或者目录的变化,使用callback形式返回结果
。
监听文件或者目录的变化,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2360,7 +2364,7 @@ createWatcher(filename: string, events: number, callback: AsyncCallback<numbe
...
@@ -2360,7 +2364,7 @@ createWatcher(filename: string, events: number, callback: AsyncCallback<numbe
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| -------------------- | ---------- |
| -------------------- | ---------- |
|
[
Watcher
](
#watcher7
)
| 文件变化监听的实例。 |
|
[
Watcher
](
#watcher7
)
|
Promise对象。返回
文件变化监听的实例。 |
**示例:**
**示例:**
```
js
```
js
...
@@ -2549,7 +2553,7 @@ Watcher是文件变化监听的实例,调用Watcher.stop()方法(同步或
...
@@ -2549,7 +2553,7 @@ Watcher是文件变化监听的实例,调用Watcher.stop()方法(同步或
stop(): Promise
<
void
>
stop(): Promise
<
void
>
以异步方法关闭watcher监听,使用promise形式返回结果
。
关闭watcher监听,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2563,7 +2567,7 @@ stop(): Promise<void>
...
@@ -2563,7 +2567,7 @@ stop(): Promise<void>
stop(callback: AsyncCallback
<
void
>
): void
stop(callback: AsyncCallback
<
void
>
): void
以异步方法关闭watcher监听,使用callback形式返回结果
。
关闭watcher监听,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2589,20 +2593,20 @@ stop(callback: AsyncCallback<void>): void
...
@@ -2589,20 +2593,20 @@ stop(callback: AsyncCallback<void>): void
close(): Promise
<
void
>
close(): Promise
<
void
>
异步关闭文件流,使用promise形式返回结果
。
关闭文件流,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ------------- |
| ------------------- | ------------- |
| Promise
<
void
>
| 表示异步关闭文件流的结果。 |
| Promise
<
void
>
|
Promise对象。返回
表示异步关闭文件流的结果。 |
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
path
);
let
ss
=
fileio
.
createStreamSync
(
path
);
ss
.
close
().
then
(
function
(){
ss
.
close
().
then
(
function
(){
console
.
info
(
"
close fileStream succe
ssfully
"
);
console
.
info
(
"
close fileStream succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
close fileStream failed with error:
"
+
err
);
console
.
info
(
"
close fileStream failed with error:
"
+
err
);
});
});
...
@@ -2613,7 +2617,7 @@ close(): Promise<void>
...
@@ -2613,7 +2617,7 @@ close(): Promise<void>
close(callback: AsyncCallback
<
void
>
): void
close(callback: AsyncCallback
<
void
>
): void
异步关闭文件流,使用callback
形式返回结果
。
异步关闭文件流,使用callback
异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2650,20 +2654,20 @@ closeSync(): void
...
@@ -2650,20 +2654,20 @@ closeSync(): void
flush(): Promise
<
void
>
flush(): Promise
<
void
>
异步刷新文件流,使用promise形式返回结果
。
刷新文件流,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------- | ------------- |
| ------------------- | ------------- |
| Promise
<
void
>
| 表示异步刷新文件流的结果。 |
| Promise
<
void
>
|
Promise对象。返回
表示异步刷新文件流的结果。 |
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
path
);
let
ss
=
fileio
.
createStreamSync
(
path
);
ss
.
flush
().
then
(
function
(){
ss
.
flush
().
then
(
function
(){
console
.
info
(
"
flush succe
ssfully
"
);
console
.
info
(
"
flush succe
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
flush failed with error:
"
+
err
);
console
.
info
(
"
flush failed with error:
"
+
err
);
});
});
...
@@ -2674,7 +2678,7 @@ flush(): Promise<void>
...
@@ -2674,7 +2678,7 @@ flush(): Promise<void>
flush(callback: AsyncCallback
<
void
>
): void
flush(callback: AsyncCallback
<
void
>
): void
异步刷新文件流,使用callback
形式返回结果
。
异步刷新文件流,使用callback
异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2716,7 +2720,7 @@ write(buffer: ArrayBuffer | string, options?: {
...
@@ -2716,7 +2720,7 @@ write(buffer: ArrayBuffer | string, options?: {
encoding?: string;
encoding?: string;
}): Promise
<
number
>
}): Promise
<
number
>
以异步方法将数据写入流文件,使用promise形式返回结果
。
将数据写入流文件,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2729,13 +2733,13 @@ write(buffer: ArrayBuffer | string, options?: {
...
@@ -2729,13 +2733,13 @@ write(buffer: ArrayBuffer | string, options?: {
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| --------------------- | -------- |
| --------------------- | -------- |
| Promise
<
number
>
| 实际写入的长度。 |
| Promise
<
number
>
|
Promise对象。返回
实际写入的长度。 |
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
fpath
,
"
r+
"
);
let
ss
=
fileio
.
createStreamSync
(
fpath
,
"
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
(
"
write succe
ssfully
and size is:
"
+
number
);
console
.
info
(
"
write succe
ed
and size is:
"
+
number
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
write failed with error:
"
+
err
);
console
.
info
(
"
write failed with error:
"
+
err
);
});
});
...
@@ -2751,7 +2755,7 @@ write(buffer: ArrayBuffer | string, options: {
...
@@ -2751,7 +2755,7 @@ write(buffer: ArrayBuffer | string, options: {
encoding?: string;
encoding?: string;
}, callback: AsyncCallback
<
number
>
): void
}, callback: AsyncCallback
<
number
>
): void
以异步方法将数据写入流文件,使用callback形式返回结果
。
将数据写入流文件,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2768,7 +2772,7 @@ write(buffer: ArrayBuffer | string, options: {
...
@@ -2768,7 +2772,7 @@ write(buffer: ArrayBuffer | string, options: {
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
(
"
write succe
ssfully
and size is:
"
+
bytesWritten
);
console
.
info
(
"
write succe
ed
and size is:
"
+
bytesWritten
);
}
}
});
});
```
```
...
@@ -2813,7 +2817,7 @@ read(buffer: ArrayBuffer, options?: {
...
@@ -2813,7 +2817,7 @@ read(buffer: ArrayBuffer, options?: {
length?: number;
length?: number;
}): Promise
<
ReadOut
>
}): Promise
<
ReadOut
>
以异步方法从流文件读取数据,使用promise形式返回结果
。
从流文件读取数据,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2826,13 +2830,13 @@ read(buffer: ArrayBuffer, options?: {
...
@@ -2826,13 +2830,13 @@ read(buffer: ArrayBuffer, options?: {
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ---------------------------------- | ------ |
| ---------------------------------- | ------ |
| Promise
<
[ReadOut](#readout)
>
| 读取的结果。 |
| Promise
<
[ReadOut](#readout)
>
|
Promise对象。返回
读取的结果。 |
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
fpath
,
"
r+
"
);
let
ss
=
fileio
.
createStreamSync
(
fpath
,
"
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 succe
ssfully
"
);
console
.
info
(
"
read data succe
ed
"
);
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
);
...
@@ -2848,7 +2852,7 @@ read(buffer: ArrayBuffer, options: {
...
@@ -2848,7 +2852,7 @@ read(buffer: ArrayBuffer, options: {
length?: number;
length?: number;
}, callback: AsyncCallback
<
ReadOut
>
): void
}, callback: AsyncCallback
<
ReadOut
>
): void
以异步方法从流文件读取数据,使用callback形式返回结果
。
从流文件读取数据,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2864,7 +2868,7 @@ read(buffer: ArrayBuffer, options: {
...
@@ -2864,7 +2868,7 @@ read(buffer: ArrayBuffer, options: {
let
ss
=
fileio
.
createStreamSync
(
fpath
,
"
r+
"
);
let
ss
=
fileio
.
createStreamSync
(
fpath
,
"
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 succe
ssfully
"
);
console
.
info
(
"
read data succe
ed
"
);
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
}
}
});
});
...
@@ -2912,20 +2916,20 @@ readSync(buffer: ArrayBuffer, options?: {
...
@@ -2912,20 +2916,20 @@ readSync(buffer: ArrayBuffer, options?: {
read(): Promise
<
Dirent
>
read(): Promise
<
Dirent
>
异步读取下一个目录项,使用promise形式返回结果
。
读取下一个目录项,使用Promise异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| -------------------------------- | ------------- |
| -------------------------------- | ------------- |
| Promise
<
[Dirent](#dirent)
>
| 表示异步读取目录项的结果。 |
| Promise
<
[Dirent](#dirent)
>
|
Promise对象。返回
表示异步读取目录项的结果。 |
**示例:**
**示例:**
```
js
```
js
let
dir
=
fileio
.
opendirSync
(
path
);
let
dir
=
fileio
.
opendirSync
(
path
);
dir
.
read
().
then
(
function
(
dirent
){
dir
.
read
().
then
(
function
(
dirent
){
console
.
log
(
"
read succe
ssfully
:
"
+
JSON
.
stringify
(
dirent
));
console
.
log
(
"
read succe
ed
:
"
+
JSON
.
stringify
(
dirent
));
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
read failed with error:
"
+
err
);
console
.
info
(
"
read failed with error:
"
+
err
);
});
});
...
@@ -2936,7 +2940,7 @@ read(): Promise<Dirent>
...
@@ -2936,7 +2940,7 @@ read(): Promise<Dirent>
read(callback: AsyncCallback
<
Dirent
>
): void
read(callback: AsyncCallback
<
Dirent
>
): void
异步读取下一个目录项,使用callback形式返回结果
。
读取下一个目录项,使用callback异步回调
。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**系统能力**
:SystemCapability.FileManagement.File.FileIO
...
@@ -2951,7 +2955,7 @@ read(callback: AsyncCallback<Dirent>): void
...
@@ -2951,7 +2955,7 @@ read(callback: AsyncCallback<Dirent>): void
dir
.
read
(
function
(
err
,
dirent
)
{
dir
.
read
(
function
(
err
,
dirent
)
{
if
(
dirent
)
{
if
(
dirent
)
{
// do something
// do something
console
.
log
(
"
read succe
ssfully
:
"
+
JSON
.
stringify
(
dirent
));
console
.
log
(
"
read succe
ed
:
"
+
JSON
.
stringify
(
dirent
));
}
}
});
});
```
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录