Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
2be6ad3b
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看板
未验证
提交
2be6ad3b
编写于
6月 28, 2022
作者:
O
openharmony_ci
提交者:
Gitee
6月 28, 2022
浏览文件
操作
浏览文件
下载
差异文件
!5978 文档修改
Merge pull request !5978 from wangbo/OpenHarmony-3.1-Release
上级
56f253fa
6ec796f1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
633 addition
and
228 deletion
+633
-228
zh-cn/application-dev/reference/apis/js-apis-document.md
zh-cn/application-dev/reference/apis/js-apis-document.md
+21
-13
zh-cn/application-dev/reference/apis/js-apis-fileio.md
zh-cn/application-dev/reference/apis/js-apis-fileio.md
+92
-201
zh-cn/application-dev/reference/apis/js-apis-filemanager.md
zh-cn/application-dev/reference/apis/js-apis-filemanager.md
+13
-8
zh-cn/application-dev/reference/apis/js-apis-securityLabel.md
...n/application-dev/reference/apis/js-apis-securityLabel.md
+181
-0
zh-cn/application-dev/reference/apis/js-apis-storage-statistics.md
...lication-dev/reference/apis/js-apis-storage-statistics.md
+326
-6
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-document.md
浏览文件 @
2be6ad3b
...
@@ -12,7 +12,7 @@ import document from '@ohos.document';
...
@@ -12,7 +12,7 @@ import document from '@ohos.document';
## document.choose
## document.choose
choose(type:string[]): Promise
<
string
>
choose(type
s
:string[]): Promise
<
string
>
通过文件管理器选择文件,异步返回文件URI,使用promise形式返回结果。
通过文件管理器选择文件,异步返回文件URI,使用promise形式返回结果。
...
@@ -22,7 +22,7 @@ choose(type:string[]): Promise<string>
...
@@ -22,7 +22,7 @@ choose(type:string[]): Promise<string>
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------------------------- |
| ------ | ------ | ---- | ---------------------------- |
| type | string[] | 否 | 限定文件选择的类型 |
| type
s
| string[] | 否 | 限定文件选择的类型 |
-
返回值:
-
返回值:
...
@@ -33,7 +33,8 @@ choose(type:string[]): Promise<string>
...
@@ -33,7 +33,8 @@ choose(type:string[]): Promise<string>
-
示例:
-
示例:
```
js
```
js
await
document
.
choose
(
type
);
let
tpyes
=
[];
document
.
choose
(
types
);
```
```
## document.choose
## document.choose
...
@@ -52,13 +53,14 @@ choose(callback:AsyncCallback<string>): void
...
@@ -52,13 +53,14 @@ choose(callback:AsyncCallback<string>): void
-
示例:
-
示例:
```
js
```
js
await
document
.
choose
(
function
(
err
,
uri
)
{
let
uri
=
""
;
document
.
choose
(
function
(
err
,
uri
)
{
//do something with uri
//do something with uri
});
});
```
```
## document.choose
## document.choose
choose(type:string[], callback:AsyncCallback
<
string
>
): void
choose(type
s
:string[], callback:AsyncCallback
<
string
>
): void
通过文件管理器选择文件,异步返回文件URI,使用callback形式返回结果。
通过文件管理器选择文件,异步返回文件URI,使用callback形式返回结果。
...
@@ -68,20 +70,22 @@ choose(type:string[], callback:AsyncCallback<string>): void
...
@@ -68,20 +70,22 @@ choose(type:string[], callback:AsyncCallback<string>): void
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- |
| -------- | --------------------------- | ---- | ---------------------------- |
| type
| string[] | 否 | 限定选择文件的类型 |
| type
s
| string[] | 否 | 限定选择文件的类型 |
| callback | AsyncCallback
<
string
>
| 是 | 异步获取对应文件URI(注:当前返回错误码) |
| callback | AsyncCallback
<
string
>
| 是 | 异步获取对应文件URI(注:当前返回错误码) |
-
示例:
-
示例:
```
js
```
js
await
document
.
choose
(
type
,
function
(
err
,
uri
)
{
let
types
=
[];
let
uri
=
""
;
document
.
choose
(
types
,
function
(
err
,
uri
)
{
//do something with uri
//do something with uri
});
});
```
```
## document.show
## document.show
show(url:string, type:string):Promise
<
number
>
show(url:string, type
s
:string):Promise
<
number
>
异步打开URI对应的文件,使用promise形式返回结果。
异步打开URI对应的文件,使用promise形式返回结果。
...
@@ -92,7 +96,7 @@ show(url:string, type:string):Promise<number>
...
@@ -92,7 +96,7 @@ show(url:string, type:string):Promise<number>
| 参数 | 类型 | 必填 | 说明 |
| 参数 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | ---------------------------- |
| ---- | ------ | ---- | ---------------------------- |
| uri | string | 是 | 待打开的文件URI |
| uri | string | 是 | 待打开的文件URI |
| type | string | 是 | 待打开文件的类型 |
| type
s
| string | 是 | 待打开文件的类型 |
-
返回值:
-
返回值:
...
@@ -103,12 +107,14 @@ show(url:string, type:string):Promise<number>
...
@@ -103,12 +107,14 @@ show(url:string, type:string):Promise<number>
-
示例:
-
示例:
```
js
```
js
await
document
.
show
(
uri
,
type
);
let
types
=
""
;
let
uri
=
""
;
document
.
show
(
uri
,
types
);
```
```
## document.show
## document.show
show(url:string, type:string, callback:AsyncCallback
<
void
>
): void
show(url:string, type
s
:string, callback:AsyncCallback
<
void
>
): void
异步打开URI对应的文件,使用callback形式返回结果。
异步打开URI对应的文件,使用callback形式返回结果。
...
@@ -119,13 +125,15 @@ show(url:string, type:string, callback:AsyncCallback<void>): void
...
@@ -119,13 +125,15 @@ show(url:string, type:string, callback:AsyncCallback<void>): void
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- |
| -------- | --------------------------- | ---- | ---------------------------- |
| uri | string | 是 | 待打开的文件URI |
| uri | string | 是 | 待打开的文件URI |
| type | string | 是 | 待打开文件的类型 |
| type
s
| string | 是 | 待打开文件的类型 |
| callback | AsyncCallback
<
void
>
| 是 | 异步打开uri对应文件(注:当前返回错误码) |
| callback | AsyncCallback
<
void
>
| 是 | 异步打开uri对应文件(注:当前返回错误码) |
-
示例:
-
示例:
```
js
```
js
await
document
.
show
(
uri
,
type
,
function
(
err
)
{
let
types
=
""
;
let
uri
=
""
;
document
.
show
(
uri
,
types
,
function
(
err
)
{
//do something
//do something
});
});
```
```
...
...
zh-cn/application-dev/reference/apis/js-apis-fileio.md
浏览文件 @
2be6ad3b
...
@@ -18,10 +18,7 @@ import fileio from '@ohos.fileio';
...
@@ -18,10 +18,7 @@ import fileio from '@ohos.fileio';
```
js
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
let
context
=
featureAbility
.
getContext
();
let
context
=
featureAbility
.
getContext
();
let
path
=
''
;
let
path
=
context
.
getFilesDir
();
context
.
getFilesDir
().
then
((
data
)
=>
{
path
=
data
;
})
```
```
...
@@ -327,52 +324,11 @@ closeSync(fd: number): void
...
@@ -327,52 +324,11 @@ closeSync(fd: number): void
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
fileio
.
closeSync
(
fd
);
fileio
.
closeSync
(
fd
);
```
```
## fileio.close<sup>7+</sup>
close(): Promise
<
void
>
关闭文件流,使用Promise异步回调。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**返回值:**
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| Promise
<
void
>
| Promise对象。无返回值。 |
**示例:**
```
js
fileio
.
close
().
then
(
function
(){
console
.
info
(
"
close file stream succeed
"
);
}).
catch
(
function
(
err
){
console
.
info
(
"
close file stream failed with error:
"
+
err
);
});
```
## fileio.close<sup>7+</sup>
close(callback: AsyncCallback
<
void
>
): void
关闭文件流,使用callback异步回调。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback
<
void
>
| 是 | 异步关闭文件流之后的回调。 |
**示例:**
```
js
fileio
.
close
(
function
(
err
){
// do something
});
```
## fileio.copyFile
## fileio.copyFile
...
@@ -397,7 +353,8 @@ copyFile(src:string | number, dest:string | number, mode?:number):Promise<voi
...
@@ -397,7 +353,8 @@ copyFile(src:string | number, dest:string | number, mode?:number):Promise<voi
**示例:**
**示例:**
```
js
```
js
fileio
.
copyFile
(
src
,
dest
).
then
(
function
(){
let
dest
=
""
;
fileio
.
copyFile
(
path
,
dest
).
then
(
function
(){
console
.
info
(
"
copyFile succeed
"
);
console
.
info
(
"
copyFile succeed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
copyFile failed with error:
"
+
err
);
console
.
info
(
"
copyFile failed with error:
"
+
err
);
...
@@ -423,7 +380,8 @@ copyFile(src: string | number, dest: string | number, mode: number, callback: As
...
@@ -423,7 +380,8 @@ copyFile(src: string | number, dest: string | number, mode: number, callback: As
**示例:**
**示例:**
```
js
```
js
fileio
.
copyFile
(
src
,
dest
,
function
(
err
)
{
let
dest
=
""
;
fileio
.
copyFile
(
path
,
dest
,
function
(
err
)
{
// do something
// do something
});
});
```
```
...
@@ -446,7 +404,8 @@ copyFileSync(src: string | number, dest: string | number, mode?: number): void
...
@@ -446,7 +404,8 @@ copyFileSync(src: string | number, dest: string | number, mode?: number): void
**示例:**
**示例:**
```
js
```
js
fileio
.
copyFileSync
(
src
,
dest
);
let
dest
=
""
;
fileio
.
copyFileSync
(
path
,
dest
);
```
```
...
@@ -589,7 +548,7 @@ openSync(path:string, flags?:number, mode?:number): number
...
@@ -589,7 +548,7 @@ openSync(path:string, flags?:number, mode?:number): number
| ------ | ------ | ---- | ------------------------------------------------------------ |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | 是 | 待打开文件的应用沙箱路径。 |
| path | string | 是 | 待打开文件的应用沙箱路径。 |
| flags | number | 否 | 打开文件的选项,必须指定如下选项中的一个,默认以只读方式打开:
<br/>
-
0o0:只读打开。
<br/>
-
0o1:只写打开。
<br/>
-
0o2:读写打开。
<br/>
同时,也可给定如下选项,以按位或的方式追加,默认不给定任何额外选项:
<br/>
-
0o100:若文件不存在,则创建文件。使用该选项时必须指定第三个参数
mode。
<br/>
-
0o200:如果追加了0o100选项,且文件已经存在,则出错。
<br/>
-
0o1000:如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。
<br/>
-
0o2000:以追加方式打开,后续写将追加到文件末尾。
<br/>
-
0o4000:如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续
IO
进行非阻塞操作。
<br/>
-
0o200000:如果path不指向目录,则出错。
<br/>
-
0o400000:如果path指向符号链接,则出错。
<br/>
-
0o4010000:以同步IO的方式打开文件。 |
| flags | number | 否 | 打开文件的选项,必须指定如下选项中的一个,默认以只读方式打开:
<br/>
-
0o0:只读打开。
<br/>
-
0o1:只写打开。
<br/>
-
0o2:读写打开。
<br/>
同时,也可给定如下选项,以按位或的方式追加,默认不给定任何额外选项:
<br/>
-
0o100:若文件不存在,则创建文件。使用该选项时必须指定第三个参数
mode。
<br/>
-
0o200:如果追加了0o100选项,且文件已经存在,则出错。
<br/>
-
0o1000:如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。
<br/>
-
0o2000:以追加方式打开,后续写将追加到文件末尾。
<br/>
-
0o4000:如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续
IO
进行非阻塞操作。
<br/>
-
0o200000:如果path不指向目录,则出错。
<br/>
-
0o400000:如果path指向符号链接,则出错。
<br/>
-
0o4010000:以同步IO的方式打开文件。 |
| mode | number | 否 | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o666。
<br/>
-
0o666:所有者具有读、写权限,所有用户组具有读、写权限,其余用户具有读、写权限。
<br/>
-
0o
640:所有者具有读、写权限,所有用户组具有读权限。
<br/>
-
0o
700:所有者具有读、写及可执行权限。
<br/>
-
0o400:所有者具有读权限。
<br/>
-
0o200:所有者具有写权限。
<br/>
-
0o100:所有者具有可执行权限。
<br/>
-
0o070:所有用户组具有读、写及可执行权限。
<br/>
-
0o040:所有用户组具有读权限。
<br/>
-
0o020:所有用户组具有写权限。
<br/>
-
0o010:所有用户组具有可执行权限。
<br/>
-
0o007:其余用户具有读、写及可执行权限。
<br/>
-
0o004:其余用户具有读权限。
<br/>
-
0o002:其余用户具有写权限。
<br/>
-
0o001:其余用户具有可执行权限。
<br/>
创建出的文件权限受umask影响,umask随进程启动确定,其修改当前不开放。 |
| mode | number | 否 | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o666。
<br/>
-
0o666:所有者具有读、写权限,所有用户组具有读、写权限,其余用户具有读、写权限。
<br/>
-
0o700:所有者具有读、写及可执行权限。
<br/>
-
0o400:所有者具有读权限。
<br/>
-
0o200:所有者具有写权限。
<br/>
-
0o100:所有者具有可执行权限。
<br/>
-
0o070:所有用户组具有读、写及可执行权限。
<br/>
-
0o040:所有用户组具有读权限。
<br/>
-
0o020:所有用户组具有写权限。
<br/>
-
0o010:所有用户组具有可执行权限。
<br/>
-
0o007:其余用户具有读、写及可执行权限。
<br/>
-
0o004:其余用户具有读权限。
<br/>
-
0o002:其余用户具有写权限。
<br/>
-
0o001:其余用户具有可执行权限。
<br/>
创建出的文件权限受umask影响,umask随进程启动确定,其修改当前不开放。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
...
@@ -598,15 +557,7 @@ openSync(path:string, flags?:number, mode?:number): number
...
@@ -598,15 +557,7 @@ openSync(path:string, flags?:number, mode?:number): number
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
,
0o102
,
0o640
);
let
fd
=
fileio
.
openSync
(
path
);
```
```
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
);
```
```
...
@@ -879,7 +830,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
...
@@ -879,7 +830,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
f
path
,
0o100
|
0o2
,
0o666
);
let
fd
=
fileio
.
openSync
(
path
,
0o100
|
0o2
,
0o666
);
fileio
.
write
(
fd
,
"
hello, world
"
).
then
(
function
(
number
){
fileio
.
write
(
fd
,
"
hello, world
"
).
then
(
function
(
number
){
console
.
info
(
"
write data to file succeed and size is:
"
+
number
);
console
.
info
(
"
write data to file succeed and size is:
"
+
number
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
...
@@ -976,7 +927,7 @@ hash(path: string, algorithm: string): Promise<string>
...
@@ -976,7 +927,7 @@ hash(path: string, algorithm: string): Promise<string>
fileio
.
hash
(
path
,
"
sha256
"
).
then
(
function
(
str
){
fileio
.
hash
(
path
,
"
sha256
"
).
then
(
function
(
str
){
console
.
info
(
"
calculate file hash succeed:
"
+
str
);
console
.
info
(
"
calculate file hash succeed:
"
+
str
);
}).
catch
(
function
(
error
){
}).
catch
(
function
(
error
){
console
.
info
(
"
calculate file hash failed with error:
"
+
err
);
console
.
info
(
"
calculate file hash failed with error:
"
+
err
or
);
});
});
```
```
...
@@ -998,7 +949,7 @@ hash(path: string, algorithm: string, callback: AsyncCallback<string>): vo
...
@@ -998,7 +949,7 @@ hash(path: string, algorithm: string, callback: AsyncCallback<string>): vo
**示例:**
**示例:**
```
js
```
js
fileio
.
hash
(
f
path
,
"
sha256
"
,
function
(
err
,
hashStr
)
{
fileio
.
hash
(
path
,
"
sha256
"
,
function
(
err
,
hashStr
)
{
if
(
hashStr
)
{
if
(
hashStr
)
{
console
.
info
(
"
calculate file hash succeed:
"
+
hashStr
);
console
.
info
(
"
calculate file hash succeed:
"
+
hashStr
);
}
}
...
@@ -1027,7 +978,7 @@ chmod(path: string, mode: number):Promise<void>
...
@@ -1027,7 +978,7 @@ chmod(path: string, mode: number):Promise<void>
**示例:**
**示例:**
```
js
```
js
fileio
.
chmod
(
path
,
mode
).
then
(
function
()
{
fileio
.
chmod
(
path
,
0o400
).
then
(
function
()
{
console
.
info
(
"
chmod succeed
"
);
console
.
info
(
"
chmod succeed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
chmod failed with error:
"
+
err
);
console
.
info
(
"
chmod failed with error:
"
+
err
);
...
@@ -1052,7 +1003,7 @@ chmod(path: string, mode: number, callback: AsyncCallback<void>): void
...
@@ -1052,7 +1003,7 @@ chmod(path: string, mode: number, callback: AsyncCallback<void>): void
**示例:**
**示例:**
```
js
```
js
fileio
.
chmod
(
path
,
mode
,
function
(
err
)
{
fileio
.
chmod
(
path
,
0o400
,
function
(
err
)
{
// do something
// do something
});
});
```
```
...
@@ -1074,7 +1025,7 @@ chmodSync(path: string, mode: number): void
...
@@ -1074,7 +1025,7 @@ chmodSync(path: string, mode: number): void
**示例:**
**示例:**
```
js
```
js
fileio
.
chmodSync
(
fpath
,
mode
);
fileio
.
chmodSync
(
path
,
0o400
);
```
```
...
@@ -1098,6 +1049,7 @@ fstat(fd: number): Promise<Stat>
...
@@ -1098,6 +1049,7 @@ fstat(fd: number): Promise<Stat>
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
fileio
.
fstat
(
fd
).
then
(
function
(
stat
){
fileio
.
fstat
(
fd
).
then
(
function
(
stat
){
console
.
info
(
"
fstat succeed:
"
+
JSON
.
stringify
(
stat
));
console
.
info
(
"
fstat succeed:
"
+
JSON
.
stringify
(
stat
));
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
...
@@ -1201,6 +1153,8 @@ ftruncate(fd: number, len: number, callback:AsyncCallback<void>): void
...
@@ -1201,6 +1153,8 @@ ftruncate(fd: number, len: number, callback:AsyncCallback<void>): void
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
let
len
=
5
;
fileio
.
ftruncate
(
fd
,
len
,
function
(
err
){
fileio
.
ftruncate
(
fd
,
len
,
function
(
err
){
// do something
// do something
});
});
...
@@ -1223,6 +1177,8 @@ ftruncateSync(fd: number, len?: number): void
...
@@ -1223,6 +1177,8 @@ ftruncateSync(fd: number, len?: number): void
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
let
len
=
5
;
fileio
.
ftruncateSync
(
fd
,
len
);
fileio
.
ftruncateSync
(
fd
,
len
);
```
```
...
@@ -1248,6 +1204,7 @@ truncate(path: string, len?: number): Promise<void>
...
@@ -1248,6 +1204,7 @@ truncate(path: string, len?: number): Promise<void>
**示例:**
**示例:**
```
js
```
js
let
len
=
5
;
fileio
.
truncate
(
path
,
len
).
then
(
function
(){
fileio
.
truncate
(
path
,
len
).
then
(
function
(){
console
.
info
(
"
truncate file succeed
"
);
console
.
info
(
"
truncate file succeed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
...
@@ -1273,6 +1230,7 @@ truncate(path: string, len: number, callback:AsyncCallback<void>): void
...
@@ -1273,6 +1230,7 @@ truncate(path: string, len: number, callback:AsyncCallback<void>): void
**示例:**
**示例:**
```
js
```
js
let
len
=
5
;
fileio
.
truncate
(
path
,
len
,
function
(
err
){
fileio
.
truncate
(
path
,
len
,
function
(
err
){
// do something
// do something
});
});
...
@@ -1295,6 +1253,7 @@ truncateSync(path: string, len?: number): void
...
@@ -1295,6 +1253,7 @@ truncateSync(path: string, len?: number): void
**示例:**
**示例:**
```
js
```
js
let
len
=
5
;
fileio
.
truncateSync
(
path
,
len
);
fileio
.
truncateSync
(
path
,
len
);
```
```
...
@@ -1353,7 +1312,7 @@ readText(filePath: string, options: {
...
@@ -1353,7 +1312,7 @@ readText(filePath: string, options: {
**示例:**
**示例:**
```
js
```
js
fileio
.
readText
(
path
,
function
(
err
,
str
){
fileio
.
readText
(
path
,
{
position
:
pos
,
length
:
len
,
encoding
:
'
UTF-8
'
},
function
(
err
,
str
){
// do something
// do something
});
});
```
```
...
@@ -1409,7 +1368,7 @@ lstat(path: string): Promise<Stat>
...
@@ -1409,7 +1368,7 @@ lstat(path: string): Promise<Stat>
**示例:**
**示例:**
```
js
```
js
fileio
.
lstat
(
path
).
then
(
function
(
stat
){
fileio
.
lstat
(
path
).
then
(
function
(
stat
){
console
.
info
(
"
get link status succeed:
"
+
number
);
console
.
info
(
"
get link status succeed:
"
+
stat
.
rdev
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
get link status failed with error:
"
+
err
);
console
.
info
(
"
get link status failed with error:
"
+
err
);
});
});
...
@@ -1462,69 +1421,6 @@ lstatSync(path:string): Stat
...
@@ -1462,69 +1421,6 @@ lstatSync(path:string): Stat
```
```
## fileio.read<sup>7+</sup>
read(buffer: ArrayBuffer, options?: {
position?: number;
offset?: number;
length?: number;
}): Promise
<
ReadOut
>
从文件读取数据,使用Promise异步回调。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ----------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer | 是 | 用于保存读取到的文件数据的缓冲区。 |
| options | Object | 否 | 支持如下选项:
<br/>
-
offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。
<br/>
-
length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。
<br/>
约束:offset+length<=buffer.size。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------- | ------ |
| Promise
<
[ReadOut](#readout)
>
| Promise对象。返回读取的结果。 |
**示例:**
```
js
fileio
.
read
(
new
ArrayBuffer
(
4096
)).
then
(
function
(
readout
){
console
.
info
(
"
read file data succeed
"
);
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
}).
catch
(
function
(
err
){
console
.
info
(
"
read file data failed with error:
"
+
err
);
});
```
## fileio.read<sup>7+</sup>
read(buffer: ArrayBuffer, options: {
position?: number;
offset?: number;
length?: number;
}, callback: AsyncCallback
<
ReadOut
>
): void
从文件读取数据,使用callback异步回调。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | 是 | 用于保存读取到的文件数据的缓冲区。 |
| options | Object | 否 | 支持如下选项:
<br/>
-
offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。
<br/>
-
length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。
<br/>
约束:offset+length<=buffer.size。 |
| callback | AsyncCallback
<
[ReadOut](#readout)
>
| 是 | 异步从文件读取数据之后的回调。 |
**示例:**
```
js
let
buf
=
new
ArrayBuffer
(
4096
);
fileio
.
read
(
buf
,
function
(
err
,
readOut
)
{
if
(
readOut
)
{
console
.
info
(
"
read file data succeed
"
);
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
}
});
```
## fileio.rename<sup>7+</sup>
## fileio.rename<sup>7+</sup>
...
@@ -1548,7 +1444,8 @@ rename(oldPath: string, newPath: string): Promise<void>
...
@@ -1548,7 +1444,8 @@ rename(oldPath: string, newPath: string): Promise<void>
**示例:**
**示例:**
```
js
```
js
fileio
.
rename
(
oldPath
,
newPath
).
then
(
function
()
{
let
newPath
=
path
+
"
123
"
;
fileio
.
rename
(
path
,
newPath
).
then
(
function
()
{
console
.
info
(
"
rename succeed
"
);
console
.
info
(
"
rename succeed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
rename failed with error:
"
+
err
);
console
.
info
(
"
rename failed with error:
"
+
err
);
...
@@ -1573,7 +1470,8 @@ rename(oldPath: string, newPath: string, callback: AsyncCallback<void>): v
...
@@ -1573,7 +1470,8 @@ rename(oldPath: string, newPath: string, callback: AsyncCallback<void>): v
**示例:**
**示例:**
```
js
```
js
fileio
.
rename
(
oldPath
,
newPath
,
function
(
err
){
let
newPath
=
path
+
"
123
"
;
fileio
.
rename
(
path
,
newPath
,
function
(
err
){
});
});
```
```
...
@@ -1594,7 +1492,8 @@ renameSync(oldPath: string, newPath: string): void
...
@@ -1594,7 +1492,8 @@ renameSync(oldPath: string, newPath: string): void
**示例:**
**示例:**
```
js
```
js
fileio
.
renameSync
(
oldPath
,
newPath
);
let
newPath
=
path
+
"
123
"
;
fileio
.
renameSync
(
path
,
newPath
);
```
```
...
@@ -1618,6 +1517,7 @@ fsync(fd: number): Promise<void>
...
@@ -1618,6 +1517,7 @@ fsync(fd: number): Promise<void>
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
fileio
.
fsync
(
fd
).
then
(
function
(){
fileio
.
fsync
(
fd
).
then
(
function
(){
console
.
info
(
"
sync data succeed
"
);
console
.
info
(
"
sync data succeed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
...
@@ -1641,7 +1541,8 @@ fsync(fd: number, callback: AsyncCallback<void>): void
...
@@ -1641,7 +1541,8 @@ fsync(fd: number, callback: AsyncCallback<void>): void
| Callback | AsyncCallback
<
void
>
| 是 | 异步将文件数据同步之后的回调。 |
| Callback | AsyncCallback
<
void
>
| 是 | 异步将文件数据同步之后的回调。 |
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
fileio
.
fsync
(
fd
,
function
(
err
){
fileio
.
fsync
(
fd
,
function
(
err
){
// do something
// do something
});
});
...
@@ -1663,6 +1564,7 @@ fsyncSync(fd: number): void
...
@@ -1663,6 +1564,7 @@ fsyncSync(fd: number): void
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
fileio
.
fyncsSync
(
fd
);
fileio
.
fyncsSync
(
fd
);
```
```
...
@@ -1686,7 +1588,8 @@ fdatasync(fd: number): Promise<void>
...
@@ -1686,7 +1588,8 @@ fdatasync(fd: number): Promise<void>
| Promise
<
void
>
| Promise对象。无返回值。 |
| Promise
<
void
>
| Promise对象。无返回值。 |
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
fileio
.
fdatasync
(
fd
).
then
(
function
(
err
)
{
fileio
.
fdatasync
(
fd
).
then
(
function
(
err
)
{
console
.
info
(
"
sync data succeed
"
);
console
.
info
(
"
sync data succeed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
...
@@ -1711,6 +1614,7 @@ fdatasync(fd: number, callback:AsyncCallback<void>): void
...
@@ -1711,6 +1614,7 @@ fdatasync(fd: number, callback:AsyncCallback<void>): void
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
fileio
.
fdatasync
(
fd
,
function
(
err
)
{
fileio
.
fdatasync
(
fd
,
function
(
err
)
{
// do something
// do something
});
});
...
@@ -1732,6 +1636,7 @@ fdatasyncSync(fd: number): void
...
@@ -1732,6 +1636,7 @@ fdatasyncSync(fd: number): void
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
let
stat
=
fileio
.
fdatasyncSync
(
fd
);
let
stat
=
fileio
.
fdatasyncSync
(
fd
);
```
```
...
@@ -1757,7 +1662,8 @@ symlink(target: string, srcPath: string): Promise<void>
...
@@ -1757,7 +1662,8 @@ symlink(target: string, srcPath: string): Promise<void>
**示例:**
**示例:**
```
js
```
js
fileio
.
symlink
(
target
,
srcPath
).
then
(
function
()
{
let
srcPath
=
""
;
fileio
.
symlink
(
path
,
srcPath
).
then
(
function
()
{
console
.
info
(
"
symlink succeed
"
);
console
.
info
(
"
symlink succeed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
symlink failed with error:
"
+
err
);
console
.
info
(
"
symlink failed with error:
"
+
err
);
...
@@ -1782,7 +1688,8 @@ symlink(target: string, srcPath: string, callback: AsyncCallback<void>): v
...
@@ -1782,7 +1688,8 @@ symlink(target: string, srcPath: string, callback: AsyncCallback<void>): v
**示例:**
**示例:**
```
js
```
js
fileio
.
symlink
(
target
,
srcPath
,
function
(
err
)
{
let
srcPath
=
""
;
fileio
.
symlink
(
path
,
srcPath
,
function
(
err
)
{
// do something
// do something
});
});
```
```
...
@@ -1804,7 +1711,8 @@ symlinkSync(target: string, srcPath: string): void
...
@@ -1804,7 +1711,8 @@ symlinkSync(target: string, srcPath: string): void
**示例:**
**示例:**
```
js
```
js
fileio
.
symlinkSync
(
target
,
srcPath
);
let
srcPath
=
""
;
fileio
.
symlinkSync
(
path
,
srcPath
);
```
```
...
@@ -1857,7 +1765,7 @@ chown(path: string, uid: number, gid: number, callback: AsyncCallback<void>
...
@@ -1857,7 +1765,7 @@ chown(path: string, uid: number, gid: number, callback: AsyncCallback<void>
**示例:**
**示例:**
```
js
```
js
let
stat
=
fileio
.
statSync
(
f
path
)
let
stat
=
fileio
.
statSync
(
path
)
fileio
.
chown
(
path
,
stat
.
uid
,
stat
.
gid
,
function
(
err
){
fileio
.
chown
(
path
,
stat
.
uid
,
stat
.
gid
,
function
(
err
){
// do something
// do something
});
});
...
@@ -1881,7 +1789,7 @@ chownSync(path: string, uid: number, gid: number): void
...
@@ -1881,7 +1789,7 @@ chownSync(path: string, uid: number, gid: number): void
**示例:**
**示例:**
```
js
```
js
let
stat
=
fileio
.
statSync
(
f
path
)
let
stat
=
fileio
.
statSync
(
path
)
fileio
.
chownSync
(
path
,
stat
.
uid
,
stat
.
gid
);
fileio
.
chownSync
(
path
,
stat
.
uid
,
stat
.
gid
);
```
```
...
@@ -1981,6 +1889,8 @@ fchmod(fd: number, mode: number): Promise<void>
...
@@ -1981,6 +1889,8 @@ fchmod(fd: number, mode: number): Promise<void>
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
let
mode
=
0o400
;
fileio
.
fchmod
(
fd
,
mode
).
then
(
function
()
{
fileio
.
fchmod
(
fd
,
mode
).
then
(
function
()
{
console
.
info
(
"
chmod succeed
"
);
console
.
info
(
"
chmod succeed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
...
@@ -2006,6 +1916,8 @@ fchmod(fd: number, mode: number, callback: AsyncCallback<void>): void
...
@@ -2006,6 +1916,8 @@ fchmod(fd: number, mode: number, callback: AsyncCallback<void>): void
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
let
mode
=
0o400
;
fileio
.
fchmod
(
fd
,
mode
,
function
(
err
)
{
fileio
.
fchmod
(
fd
,
mode
,
function
(
err
)
{
// do something
// do something
});
});
...
@@ -2028,7 +1940,9 @@ fchmodSync(fd: number, mode: number): void
...
@@ -2028,7 +1940,9 @@ fchmodSync(fd: number, mode: number): void
**示例:**
**示例:**
```
js
```
js
fileio
.
fchmodSync
(
fd
,
mode
);
let
fd
=
fileio
.
openSync
(
path
);
let
mode
=
0o400
;
fileio
.
fchmodSync
(
fd
,
mode
);
```
```
...
@@ -2078,6 +1992,7 @@ createStream(path: string, mode: string, callback: AsyncCallback<Stream>):
...
@@ -2078,6 +1992,7 @@ createStream(path: string, mode: string, callback: AsyncCallback<Stream>):
**示例:**
**示例:**
```
js
```
js
let
mode
=
0o400
;
fileio
.
createStream
(
path
,
mode
,
function
(
err
,
stream
){
fileio
.
createStream
(
path
,
mode
,
function
(
err
,
stream
){
// do something
// do something
});
});
...
@@ -2130,6 +2045,8 @@ fdopenStream(fd: number, mode: string): Promise<Stream>
...
@@ -2130,6 +2045,8 @@ fdopenStream(fd: number, mode: string): Promise<Stream>
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
let
mode
=
0o400
;
fileio
.
fdopenStream
(
fd
,
mode
).
then
(
function
(
stream
){
fileio
.
fdopenStream
(
fd
,
mode
).
then
(
function
(
stream
){
console
.
info
(
"
openStream succeed
"
);
console
.
info
(
"
openStream succeed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
...
@@ -2155,6 +2072,8 @@ fdopenStream(fd: number, mode: string, callback: AsyncCallback<Stream>): v
...
@@ -2155,6 +2072,8 @@ fdopenStream(fd: number, mode: string, callback: AsyncCallback<Stream>): v
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
let
mode
=
0o400
;
fileio
.
fdopenStream
(
fd
,
mode
,
function
(
err
,
stream
)
{
fileio
.
fdopenStream
(
fd
,
mode
,
function
(
err
,
stream
)
{
// do something
// do something
});
});
...
@@ -2182,6 +2101,7 @@ fdopenStreamSync(fd: number, mode: string): Stream
...
@@ -2182,6 +2101,7 @@ fdopenStreamSync(fd: number, mode: string): Stream
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
let
ss
=
fileio
.
fdopenStreamSync
(
fd
,
"
r+
"
);
let
ss
=
fileio
.
fdopenStreamSync
(
fd
,
"
r+
"
);
```
```
...
@@ -2208,6 +2128,7 @@ fchown(fd: number, uid: number, gid: number): Promise<void>
...
@@ -2208,6 +2128,7 @@ fchown(fd: number, uid: number, gid: number): Promise<void>
**示例:**
**示例:**
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
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 succeed
"
);
console
.
info
(
"
chown succeed
"
);
...
@@ -2235,7 +2156,8 @@ fchown(fd: number, uid: number, gid: number, callback: AsyncCallback<void>
...
@@ -2235,7 +2156,8 @@ fchown(fd: number, uid: number, gid: number, callback: AsyncCallback<void>
**示例:**
**示例:**
```
js
```
js
let
stat
=
fileio
.
statSync
(
fpath
);
let
fd
=
fileio
.
openSync
(
path
);
let
stat
=
fileio
.
statSync
(
path
);
fileio
.
fchown
(
fd
,
stat
.
uid
,
stat
.
gid
,
function
(
err
){
fileio
.
fchown
(
fd
,
stat
.
uid
,
stat
.
gid
,
function
(
err
){
// do something
// do something
});
});
...
@@ -2259,7 +2181,8 @@ fchownSync(fd: number, uid: number, gid: number): void
...
@@ -2259,7 +2181,8 @@ fchownSync(fd: number, uid: number, gid: number): void
**示例:**
**示例:**
```
js
```
js
let
stat
=
fileio
.
statSync
(
fpath
);
let
fd
=
fileio
.
openSync
(
path
);
let
stat
=
fileio
.
statSync
(
path
);
fileio
.
fchownSync
(
fd
,
stat
.
uid
,
stat
.
gid
);
fileio
.
fchownSync
(
fd
,
stat
.
uid
,
stat
.
gid
);
```
```
...
@@ -2364,6 +2287,8 @@ createWatcher(filename: string, events: number, callback: AsyncCallback<numbe
...
@@ -2364,6 +2287,8 @@ createWatcher(filename: string, events: number, callback: AsyncCallback<numbe
**示例:**
**示例:**
```
js
```
js
let
filename
=
path
+
"
/test.txt
"
;
let
events
=
1
;
fileio
.
createWatcher
(
filename
,
events
,
function
(
watcher
){
fileio
.
createWatcher
(
filename
,
events
,
function
(
watcher
){
// do something
// do something
});
});
...
@@ -2498,7 +2423,7 @@ isFile(): boolean
...
@@ -2498,7 +2423,7 @@ isFile(): boolean
**示例:**
**示例:**
```
js
```
js
let
isFile
=
fileio
.
statSync
(
f
path
).
isFile
();
let
isFile
=
fileio
.
statSync
(
path
).
isFile
();
```
```
...
@@ -2600,7 +2525,7 @@ close(): Promise<void>
...
@@ -2600,7 +2525,7 @@ close(): Promise<void>
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
path
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
ss
.
close
().
then
(
function
(){
ss
.
close
().
then
(
function
(){
console
.
info
(
"
close fileStream succeed
"
);
console
.
info
(
"
close fileStream succeed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
...
@@ -2641,7 +2566,7 @@ closeSync(): void
...
@@ -2641,7 +2566,7 @@ closeSync(): void
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
path
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
ss
.
closeSync
();
ss
.
closeSync
();
```
```
...
@@ -2661,7 +2586,7 @@ flush(): Promise<void>
...
@@ -2661,7 +2586,7 @@ flush(): Promise<void>
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
path
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
ss
.
flush
().
then
(
function
(){
ss
.
flush
().
then
(
function
(){
console
.
info
(
"
flush succeed
"
);
console
.
info
(
"
flush succeed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
...
@@ -2685,7 +2610,7 @@ flush(callback: AsyncCallback<void>): void
...
@@ -2685,7 +2610,7 @@ flush(callback: AsyncCallback<void>): void
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
path
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
ss
.
flush
(
function
(
err
)
{
ss
.
flush
(
function
(
err
)
{
// do something
// do something
});
});
...
@@ -2702,7 +2627,7 @@ flushSync(): void
...
@@ -2702,7 +2627,7 @@ flushSync(): void
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
path
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
ss
.
flushSync
();
ss
.
flushSync
();
```
```
...
@@ -2733,7 +2658,7 @@ write(buffer: ArrayBuffer | string, options?: {
...
@@ -2733,7 +2658,7 @@ write(buffer: ArrayBuffer | string, options?: {
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
f
path
,
"
r+
"
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
ss
.
write
(
"
hello, world
"
,{
offset
:
1
,
length
:
5
,
position
:
5
,
encoding
:
'
utf-8
'
}).
then
(
function
(
number
){
ss
.
write
(
"
hello, world
"
,{
offset
:
1
,
length
:
5
,
position
:
5
,
encoding
:
'
utf-8
'
}).
then
(
function
(
number
){
console
.
info
(
"
write succeed and size is:
"
+
number
);
console
.
info
(
"
write succeed and size is:
"
+
number
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
...
@@ -2764,7 +2689,7 @@ write(buffer: ArrayBuffer | string, options: {
...
@@ -2764,7 +2689,7 @@ write(buffer: ArrayBuffer | string, options: {
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
f
path
,
"
r+
"
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
ss
.
write
(
"
hello, world
"
,
{
offset
:
1
,
length
:
5
,
position
:
5
,
encoding
:
'
utf-8
'
},
function
(
err
,
bytesWritten
)
{
ss
.
write
(
"
hello, world
"
,
{
offset
:
1
,
length
:
5
,
position
:
5
,
encoding
:
'
utf-8
'
},
function
(
err
,
bytesWritten
)
{
if
(
bytesWritten
)
{
if
(
bytesWritten
)
{
// do something
// do something
...
@@ -2800,7 +2725,7 @@ writeSync(buffer: ArrayBuffer | string, options?: {
...
@@ -2800,7 +2725,7 @@ writeSync(buffer: ArrayBuffer | string, options?: {
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
f
path
,
"
r+
"
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
let
num
=
ss
.
writeSync
(
"
hello, world
"
,
{
offset
:
1
,
length
:
5
,
position
:
5
,
encoding
:
'
utf-8
'
});
let
num
=
ss
.
writeSync
(
"
hello, world
"
,
{
offset
:
1
,
length
:
5
,
position
:
5
,
encoding
:
'
utf-8
'
});
```
```
...
@@ -2830,10 +2755,10 @@ read(buffer: ArrayBuffer, options?: {
...
@@ -2830,10 +2755,10 @@ read(buffer: ArrayBuffer, options?: {
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
f
path
,
"
r+
"
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
ss
.
read
(
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
length
:
5
,
position
:
5
}).
then
(
function
(
readout
){
ss
.
read
(
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
length
:
5
,
position
:
5
}).
then
(
function
(
readout
){
console
.
info
(
"
read data succeed
"
);
console
.
info
(
"
read data succeed
"
);
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
read
O
ut
.
buffer
)));
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
read
o
ut
.
buffer
)));
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
read data failed with error:
"
+
err
);
console
.
info
(
"
read data failed with error:
"
+
err
);
});
});
...
@@ -2861,7 +2786,7 @@ read(buffer: ArrayBuffer, options: {
...
@@ -2861,7 +2786,7 @@ read(buffer: ArrayBuffer, options: {
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
f
path
,
"
r+
"
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
ss
.
read
(
new
ArrayBuffer
(
4096
),{
offset
:
1
,
length
:
5
,
position
:
5
},
function
(
err
,
readOut
)
{
ss
.
read
(
new
ArrayBuffer
(
4096
),{
offset
:
1
,
length
:
5
,
position
:
5
},
function
(
err
,
readOut
)
{
if
(
readOut
)
{
if
(
readOut
)
{
console
.
info
(
"
read data succeed
"
);
console
.
info
(
"
read data succeed
"
);
...
@@ -2898,7 +2823,7 @@ readSync(buffer: ArrayBuffer, options?: {
...
@@ -2898,7 +2823,7 @@ readSync(buffer: ArrayBuffer, options?: {
**示例:**
**示例:**
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
f
path
,
"
r+
"
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
let
num
=
ss
.
readSync
(
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
length
:
5
,
position
:
5
});
let
num
=
ss
.
readSync
(
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
length
:
5
,
position
:
5
});
```
```
...
@@ -2923,7 +2848,7 @@ read(): Promise<Dirent>
...
@@ -2923,7 +2848,7 @@ read(): Promise<Dirent>
**示例:**
**示例:**
```
js
```
js
let
dir
=
fileio
.
opendirSync
(
path
);
dir
=
fileio
.
opendirSync
(
path
);
dir
.
read
().
then
(
function
(
dirent
){
dir
.
read
().
then
(
function
(
dirent
){
console
.
log
(
"
read succeed:
"
+
JSON
.
stringify
(
dirent
));
console
.
log
(
"
read succeed:
"
+
JSON
.
stringify
(
dirent
));
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
...
@@ -2947,7 +2872,7 @@ read(callback: AsyncCallback<Dirent>): void
...
@@ -2947,7 +2872,7 @@ read(callback: AsyncCallback<Dirent>): void
**示例:**
**示例:**
```
js
```
js
let
dir
=
fileio
.
opendirSync
(
path
);
dir
=
fileio
.
opendirSync
(
path
);
dir
.
read
(
function
(
err
,
dirent
)
{
dir
.
read
(
function
(
err
,
dirent
)
{
if
(
dirent
)
{
if
(
dirent
)
{
// do something
// do something
...
@@ -2972,45 +2897,11 @@ readSync(): Dirent
...
@@ -2972,45 +2897,11 @@ readSync(): Dirent
**示例:**
**示例:**
```
js
```
js
let
dir
=
fileio
.
opendirSync
(
path
);
dir
=
fileio
.
opendirSync
(
path
);
let
dirent
=
dir
.
readSync
();
let
dirent
=
dir
.
readSync
();
```
```
### close
close(): Promise
<
void
>
异步关闭目录,使用promise形式返回结果。目录被关闭后,Dir中持有的文件描述将被释放,后续将无法从Dir中读取目录项。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**示例:**
```
js
let
dir
=
fileio
.
opendirSync
(
path
);
dir
.
close
().
then
(
function
(
err
){
console
.
info
(
"
close dir successfully
"
);
});
```
### close
close(callback: AsyncCallback
<
void
>
): void
异步关闭目录,使用callback形式返回结果。目录被关闭后,Dir中持有的文件描述将被释放,后续将无法从Dir中读取目录项。
**系统能力**
:SystemCapability.FileManagement.File.FileIO
**示例:**
```
js
let
dir
=
fileio
.
opendirSync
(
path
);
dir
.
close
(
function
(
err
){
console
.
info
(
"
close dir successfully
"
);
});
```
### closeSync
### closeSync
closeSync(): void
closeSync(): void
...
@@ -3021,7 +2912,7 @@ closeSync(): void
...
@@ -3021,7 +2912,7 @@ closeSync(): void
**示例:**
**示例:**
```
js
```
js
let
dir
=
fileio
.
opendirSync
(
path
);
dir
=
fileio
.
opendirSync
(
path
);
dir
.
closeSync
();
dir
.
closeSync
();
```
```
...
@@ -3054,7 +2945,7 @@ isBlockDevice(): boolean
...
@@ -3054,7 +2945,7 @@ isBlockDevice(): boolean
**示例:**
**示例:**
```
js
```
js
let
dir
=
fileio
.
opendirSync
(
path
);
dir
=
fileio
.
opendirSync
(
path
);
let
isBLockDevice
=
dir
.
readSync
().
isBlockDevice
();
let
isBLockDevice
=
dir
.
readSync
().
isBlockDevice
();
```
```
...
@@ -3074,7 +2965,7 @@ isCharacterDevice(): boolean
...
@@ -3074,7 +2965,7 @@ isCharacterDevice(): boolean
**示例:**
**示例:**
```
js
```
js
let
dir
=
fileio
.
opendirSync
(
path
);
dir
=
fileio
.
opendirSync
(
path
);
let
isCharacterDevice
=
dir
.
readSync
().
isCharacterDevice
();
let
isCharacterDevice
=
dir
.
readSync
().
isCharacterDevice
();
```
```
...
@@ -3094,7 +2985,7 @@ isDirectory(): boolean
...
@@ -3094,7 +2985,7 @@ isDirectory(): boolean
**示例:**
**示例:**
```
js
```
js
let
dir
=
fileio
.
opendirSync
(
path
);
dir
=
fileio
.
opendirSync
(
path
);
let
isDirectory
=
dir
.
readSync
().
isDirectory
();
let
isDirectory
=
dir
.
readSync
().
isDirectory
();
```
```
...
@@ -3114,7 +3005,7 @@ isFIFO(): boolean
...
@@ -3114,7 +3005,7 @@ isFIFO(): boolean
**示例:**
**示例:**
```
js
```
js
let
dir
=
fileio
.
opendirSync
(
path
);
dir
=
fileio
.
opendirSync
(
path
);
let
isFIFO
=
dir
.
readSync
().
isFIFO
();
let
isFIFO
=
dir
.
readSync
().
isFIFO
();
```
```
...
@@ -3134,7 +3025,7 @@ isFile(): boolean
...
@@ -3134,7 +3025,7 @@ isFile(): boolean
**示例:**
**示例:**
```
js
```
js
let
dir
=
fileio
.
opendirSync
(
path
);
dir
=
fileio
.
opendirSync
(
path
);
let
isFile
=
dir
.
readSync
().
isFile
();
let
isFile
=
dir
.
readSync
().
isFile
();
```
```
...
@@ -3154,7 +3045,7 @@ isSocket(): boolean
...
@@ -3154,7 +3045,7 @@ isSocket(): boolean
**示例:**
**示例:**
```
js
```
js
let
dir
=
fileio
.
opendirSync
(
d
path
);
dir
=
fileio
.
opendirSync
(
path
);
let
isSocket
=
dir
.
readSync
().
isSocket
();
let
isSocket
=
dir
.
readSync
().
isSocket
();
```
```
...
@@ -3174,6 +3065,6 @@ isSymbolicLink(): boolean
...
@@ -3174,6 +3065,6 @@ isSymbolicLink(): boolean
**示例:**
**示例:**
```
js
```
js
let
dir
=
fileio
.
opendirSync
(
path
);
dir
=
fileio
.
opendirSync
(
path
);
let
isSymbolicLink
=
dir
.
readSync
().
isSymbolicLink
();
let
isSymbolicLink
=
dir
.
readSync
().
isSymbolicLink
();
```
```
zh-cn/application-dev/reference/apis/js-apis-filemanager.md
浏览文件 @
2be6ad3b
...
@@ -111,7 +111,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
...
@@ -111,7 +111,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
```
js
```
js
// 获取目录下所有文件
// 获取目录下所有文件
// 通过listFile、getRoot获取的文件uri
// 通过listFile、getRoot获取的文件uri
let
media_path
=
file
.
path
let
media_path
=
""
filemanager
.
listFile
(
media_path
,
"
file
"
)
filemanager
.
listFile
(
media_path
,
"
file
"
)
.
then
((
fileInfo
)
=>
{
.
then
((
fileInfo
)
=>
{
if
(
Array
.
isArray
(
fileInfo
))
{
if
(
Array
.
isArray
(
fileInfo
))
{
...
@@ -120,6 +120,9 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
...
@@ -120,6 +120,9 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
}
}
}
}
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
err
)
console
.
log
(
err
)
});
});
```
```
...
@@ -152,7 +155,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
...
@@ -152,7 +155,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
```
js
```
js
// 通过listFile、getRoot获取的文件path
// 通过listFile、getRoot获取的文件path
let
fileInfos
=
await
filemanager
.
getRoot
();
let
fileInfos
=
filemanager
.
getRoot
();
let
media_path
=
""
;
let
media_path
=
""
;
for
(
let
i
=
0
;
i
<
fileInfos
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
fileInfos
.
length
;
i
++
)
{
if
(
fileInfos
[
i
].
name
==
"
image_album
"
)
{
if
(
fileInfos
[
i
].
name
==
"
image_album
"
)
{
...
@@ -197,7 +200,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
...
@@ -197,7 +200,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
| 类型 | 说明 |
| 类型 | 说明 |
| --- | -- |
| --- | -- |
|
Promise
<
string
>
| 文件uri |
|
string
| 文件uri |
-
异常
-
异常
| 错误名称 | 错误类型 | 错误码 |说明 |
| 错误名称 | 错误类型 | 错误码 |说明 |
...
@@ -211,7 +214,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
...
@@ -211,7 +214,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
```
js
```
js
// 创建文件,返回文件uri
// 创建文件,返回文件uri
let
media_path
=
file
.
uri
// 通过listFile、getRoot获取的文件uri
let
media_path
=
""
// 通过listFile、getRoot获取的文件uri
let
name
=
"
xxx.jpg
"
// 待保存文件的后缀
let
name
=
"
xxx.jpg
"
// 待保存文件的后缀
filemanager
.
createFile
(
media_path
,
name
).
then
((
uri
)
=>
{
filemanager
.
createFile
(
media_path
,
name
).
then
((
uri
)
=>
{
// 返回uri给应用
// 返回uri给应用
...
@@ -252,13 +255,15 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
...
@@ -252,13 +255,15 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
```
js
```
js
// 创建文件,返回文件uri
// 创建文件,返回文件uri
// 通过listFile、getRoot获取的文件uri
// 通过listFile、getRoot获取的文件uri
let
media_path
=
file
.
path
let
media_path
=
""
// 待保存文件的后缀
// 待保存文件的后缀
let
name
=
"
xxx.jpg
"
let
name
=
"
xxx.jpg
"
filemanager
.
createFile
(
media_path
,
name
,
(
err
,
uri
)
=>
{
let
dev
=
""
;
filemanager
.
createFile
(
media_path
,
name
,
{
DevInfo
:
dev
},
function
(
err
,
uri
)
{
// 返回uri给应用
// 返回uri给应用
console
.
log
(
"
file uri:
"
+
uri
);
console
.
log
(
"
file uri:
"
+
uri
);
});
});
```
```
## FileInfo
## FileInfo
...
...
zh-cn/application-dev/reference/apis/js-apis-securityLabel.md
0 → 100644
浏览文件 @
2be6ad3b
# 数据标签
>  **说明:**
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
该模块提供文件数据安全等级的相关功能:向应用程序提供查询、设置文件数据安全等级的JS接口。
## 导入模块
```
js
import
securityLabel
from
'
@ohos.securityLabel
'
;
```
## 使用说明
使用该功能模块对文件/目录进行操作前,需要先获取其应用沙箱路径,获取方式及其接口用法请参考:
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
let
context
=
featureAbility
.
getContext
();
let
path
=
context
.
getFilesDir
();
```
## securityLabel.setSecurityLabel
setSecurityLabel(path:string, dataLevel:string):Promise
<
void
>
以异步方法设置数据标签,以promise形式返回结果。
**系统能力**
:SystemCapability.FileManagement.File.DistributedFile
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | -------------------------------------------- |
| path | string | 是 | 文件路径 |
| dataLevel | string | 是 | 文件等级属性,只支持"s0","s1","s2","s3","s4" |
**返回值:**
| 类型 | 说明 |
| ------------------- | ---------------- |
| Promise
<
void
>
| Promise实例,用于异步获取结果。本调用将返回空值。|
**示例:**
```
js
let
dataLevel
=
"
s4
"
;
securityLabel
.
setSecurityLabel
(
path
,
dataLevel
).
then
(
function
(){
console
.
info
(
"
setSecurityLabel successfully
"
);
}).
catch
(
function
(
error
){
console
.
info
(
"
setSecurityLabel failed with error:
"
+
error
);
});
```
## securityLabel.setSecurityLabel
setSecurityLabel(path:string, dataLevel:string, callback: AsyncCallback
<
void
>
):void
以异步方法设置数据标签,以callback形式返回结果。
**系统能力**
:SystemCapability.FileManagement.File.DistributedFile
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | -------------------------------------------- |
| path | string | 是 | 文件路径 |
| dataLevel | string | 是 | 文件等级属性,只支持"s0","s1","s2","s3","s4" |
| callback | AsyncCallback
<
void
>
| 是 | 是否设置数据标签之后的回调 |
**示例:**
```
js
let
dataLevel
=
"
s4
"
;
securityLabel
.
setSecurityLabel
(
path
,
dataLevel
,
function
(
error
){
console
.
info
(
"
setSecurityLabel:
"
+
JSON
.
stringify
(
error
));
});
```
## securityLabel.setSecurityLabelSync
setSecurityLabelSync(path:string, dataLevel:string):void
以同步方法设置数据标签。
**系统能力**
:SystemCapability.FileManagement.File.DistributedFile
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | -------------------------------------------- |
| path | string | 是 | 文件路径 |
| dataLevel | string | 是 | 文件等级属性,只支持"s0","s1","s2","s3","s4" |
**示例:**
```
js
let
dataLevel
=
"
s4
"
;
securityLabel
.
setSecurityLabelSync
(
path
,
dataLevel
);
```
## securityLabel.getSecurityLabel
getSecurityLabel(path:string):Promise
<
string
>
异步方法获取数据标签,以promise形式返回结果。
**系统能力**
:SystemCapability.FileManagement.File.DistributedFile
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------- |
| path | string | 是 | 文件路径 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------ |
| Promise
<
string
>
| 返回数据标签 |
**示例:**
```
js
let
dataLevel
=
"
s4
"
;
securityLabel
.
getSecurityLabel
(
path
).
then
(
function
(
dataLevel
){
console
.
log
(
"
getSecurityLabel successfully:
"
+
dataLevel
);
}).
catch
(
function
(
error
){
console
.
log
(
"
getSecurityLabel failed with error:
"
+
error
);
});
```
## securityLabel.getSecurityLabel
getSecurityLabel(path:string, callback:AsyncCallback
<
string
>
): void
异步方法获取数据标签,以callback形式返回结果。
**系统能力**
:SystemCapability.FileManagement.File.DistributedFile
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | -------------------------- |
| path | string | 是 | 文件路径 |
| callback | AsyncCallback
<
string
>
| 是 | 异步获取数据标签之后的回调 |
**示例:**
```
js
let
dataLevel
=
"
s4
"
;
securityLabel
.
getSecurityLabel
(
path
,
function
(
error
,
dataLevel
){
console
.
log
(
"
getSecurityLabel successfully:
"
+
dataLevel
);
});
```
## securityLabel.getSecurityLabelSync
getSecurityLabelSync(path:string):string
以同步方法获取数据标签。
**系统能力**
:SystemCapability.FileManagement.File.DistributedFile
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------- |
| path | string | 是 | 文件路径 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------ |
| string | 返回数据标签 |
**示例:**
```
js
let
result
=
securityLabel
.
getSecurityLabelSync
(
path
);
console
.
log
(
"
getSecurityLabel successfully:
"
+
result
);
```
zh-cn/application-dev/reference/apis/js-apis-storage-statistics.md
浏览文件 @
2be6ad3b
...
@@ -4,14 +4,13 @@
...
@@ -4,14 +4,13 @@
>
>
> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - API 9当前为Canary版本,仅供试用,不保证接口可稳定调用。
> - API 9当前为Canary版本,仅供试用,不保证接口可稳定调用。
> - 本模块接口为系统接口,三方应用不支持调用。
该模块提供空间查询相关的常用功能:包括对内外卡的空间查询,对应用分类数据统计的查询,对应用数据的查询等。
该模块提供空间查询相关的常用功能:包括对内外卡的空间查询,对应用分类数据统计的查询,对应用数据的查询等。
## 导入模块
## 导入模块
```
js
```
js
import
storage
s
tatistics
from
"
@ohos.storageStatistics
"
;
import
storage
S
tatistics
from
"
@ohos.storageStatistics
"
;
```
```
## storagestatistics.getTotalSizeOfVolume
## storagestatistics.getTotalSizeOfVolume
...
@@ -20,8 +19,12 @@ getTotalSizeOfVolume(volumeUuid: string): Promise<number>
...
@@ -20,8 +19,12 @@ getTotalSizeOfVolume(volumeUuid: string): Promise<number>
异步获取指定卷的总空间大小,以promise方式返回。
异步获取指定卷的总空间大小,以promise方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
...
@@ -51,8 +54,12 @@ getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback<number>):v
...
@@ -51,8 +54,12 @@ getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback<number>):v
异步获取指定卷的总空间大小,以callback方式返回。
异步获取指定卷的总空间大小,以callback方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
...
@@ -78,8 +85,12 @@ getFreeSizeOfVolume(volumeUuid: string): Promise<number>
...
@@ -78,8 +85,12 @@ getFreeSizeOfVolume(volumeUuid: string): Promise<number>
异步获取指定卷的可用空间大小,以promise方式返回。
异步获取指定卷的可用空间大小,以promise方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
...
@@ -110,8 +121,12 @@ getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback<number>):vo
...
@@ -110,8 +121,12 @@ getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback<number>):vo
异步获取指定卷的可用空间大小,以callback方式返回。
异步获取指定卷的可用空间大小,以callback方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
...
@@ -135,8 +150,12 @@ getBundleStats(packageName: string): Promise<BundleStats>
...
@@ -135,8 +150,12 @@ getBundleStats(packageName: string): Promise<BundleStats>
异步获取应用存储数据,以promise方式返回。
异步获取应用存储数据,以promise方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
...
@@ -166,8 +185,12 @@ getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>)
...
@@ -166,8 +185,12 @@ getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>)
异步获取应用存储数据,以callback方式返回。
异步获取应用存储数据,以callback方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
...
@@ -185,14 +208,311 @@ getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>)
...
@@ -185,14 +208,311 @@ getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>)
});
});
```
```
## storagestatistics.getCurrentBundleStats<sup>9+</sup>
getCurrentBundleStats(): Promise
<BundleStats>
第三方应用异步获取占用空间,以promise方式返回。
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
-
返回值
| 类型 | 说明 |
| ------------------------------------------ | -------------------------- |
| Promise
<
[Bundlestats](#bundlestats)
>
| 返回指定卷上的应用存储状态 |
-
示例
```
js
let
bundleStats
=
storageStatistics
.
getCurrentBundleStats
();
console
.
info
(
"
getCurrentBundleStats successfully:
"
+
JSON
.
stringify
(
bundleStats
));
```
## storagestatistics.getCurrentBundleStats<sup>9+</sup>
getCurrentBundleStats(callback: AsyncCallback
<BundleStats>
): void
第三方应用异步获取占用空间,以callback方式返回。
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| callback | callback:AsyncCallback
<
[BundleStats](#bundlestats)
>
| 是 | 获取指定卷上的应用存储状态之后的回调 |
-
示例
```
js
storagestatistics
.
getCurrentBundleStats
(
function
(
error
,
bundleStats
){
// do something
console
.
info
(
"
getCurrentBundleStats successfully:
"
+
JSON
.
stringify
(
bundleStats
));
});
```
## BundleStats<sup>9+</sup>
## BundleStats<sup>9+</sup>
**系统能力**
:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics。
**系统能力**
:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics。
### 属性
-
属性
| 名称 | 类型 | 说明 |
| --------- | ------ | -------------- |
| appSize | number | app数据大小 |
| cacheSize | number | 缓存数据大小 |
| dataSize | number | 应用总数据大小 |
## storagestatistics.getTotalSize<sup>9+</sup>
getTotalSize(): Promise
<number>
获取内卡的总空间大小,以promise方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
返回值
| 类型 | 说明 |
| --------------------- | ------------------ |
| Promise
<
number
>
| 返回内卡的总空间大小 |
-
示例
```
js
let
number
=
storageStatistics
.
getTotalSize
();
console
.
info
(
"
getTotalSize successfully:
"
+
JSON
.
stringify
(
number
));
```
## storagestatistics.getTotalSize<sup>9+</sup>
getTotalSize(callback: AsyncCallback
<number>
): void
获取内卡的总空间大小,以callback方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------ | ---- | ------------------------ |
| callback | callback:AsyncCallback
<
number
>
| 是 | 获取内卡的总空间大小之后的回调 |
-
示例
```
js
storagestatistics
.
getTotalSize
(
function
(
error
,
number
){
// do something
console
.
info
(
"
getTotalSize successfully:
"
+
JSON
.
stringify
(
number
));
});
```
## storagestatistics.getFreeSize<sup>9+</sup>
getFreeSize(): Promise
<number>
获取内卡的可用空间大小,以promise方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
返回值
| 类型 | 说明 |
| --------------------- | ------------------ |
| Promise
<
number
>
| 返回内卡的可用空间大小 |
-
示例
```
js
let
number
=
storageStatistics
.
getFreeSize
();
console
.
info
(
"
getFreeSize successfully:
"
+
JSON
.
stringify
(
number
));
```
## storagestatistics.getFreeSize<sup>9+</sup>
getFreeSize(callback: AsyncCallback
<number>
): void
获取内卡的可用空间大小,以callback方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------ | ---- | ------------------------- |
| callback | callback:AsyncCallback
<
number
>
| 是 | 获取内卡的可用空间大小之后的回调 |
-
示例
```
js
storagestatistics
.
getFreeSize
(
function
(
error
,
number
){
// do something
console
.
info
(
"
getFreeSize successfully:
"
+
JSON
.
stringify
(
number
));
});
```
## storagestatistics.getSystemSize<sup>9+</sup>
getSystemSize(): Promise
<
number
>
异步获取系统空间大小,以promise方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
返回值
| 类型 | 说明 |
| --------------------- | ---------------- |
| Promise
<
number
>
| 返回系统空间大小 |
-
示例
```
js
storagestatistics
.
getSystemSize
().
then
(
function
(
number
){
console
.
info
(
"
getSystemSize successfully:
"
+
number
);
}).
catch
(
function
(
err
){
console
.
info
(
"
getSystemSize failed with error:
"
+
err
);
});
```
## storagestatistics.getSystemSize<sup>9+</sup>
getSystemSize(callback:AsyncCallback
<
number
>
):void
异步获取系统空间大小,以callback方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| callback | callback:AsyncCallback
<
number
>
| 是 | 获取系统空间大小之后的回调 |
-
示例
```
js
storagestatistics
.
getSystemSize
(
function
(
error
,
number
){
// do something
console
.
info
(
"
getSystemSize successfully:
"
+
number
);
});
```
## storagestatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId?: string): Promise
<
StorageStats
>
异步获取用户各类别数据大小,以promise方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------ | ---- | ---- |
| userId | string | 否 | 用户id
<br/>
确认当前用户:
<br/>
-
有值:表示指定用户。
<br/>
-
无值:表示当前用户。|
-
返回值
| 类型 | 说明 |
| --------------------- | ---------------- |
| Promise
<
[StorageStats](#StorageStats)
>
| 返回各类别数据大小 |
-
示例
```
js
let
userId
=
""
;
storagestatistics
.
getUserStorageStats
(
userId
).
then
(
function
(
StorageStats
){
console
.
info
(
"
getUserStorageStats successfully:
"
+
JSON
.
stringify
(
StorageStats
));
}).
catch
(
function
(
err
){
console
.
info
(
"
getUserStorageStats failed with error:
"
+
err
);
});
```
## storagestatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId?: string, callback:AsyncCallback
<
StorageStats
>
):void
异步获取用户各类别数据大小,以callback方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| userId | string | 否 | 用户id
<br/>
确认当前用户:
<br/>
-
有值:表示指定用户。
<br/>
-
无值:表示当前用户。 |
| callback | callback:AsyncCallback
<
[StorageStats](#StorageStats)
>
| 是 | 返回各类别数据大小之后的回调 |
-
示例
```
js
let
userId
=
""
;
storagestatistics
.
getUserStorageStats
(
userId
,
function
(
error
,
StorageStats
){
// do something
console
.
info
(
"
getUserStorageStats successfully:
"
+
JSON
.
stringify
(
StorageStats
));
});
```
## StorageStats<sup>9+</sup>
**系统能力**
:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics。
-
属性
| 名称 | 类型 | 说明 |
| 名称 | 类型 | 说明 |
| --------- | ------ | -------------- |
| --------- | ------ | -------------- |
| appSize
<sup>
9+
</sup>
| number | app数据大小 |
| total | number | 内卡总空间大小 |
| cacheSize
<sup>
9+
</sup>
| number | 缓存数据大小 |
| audio | number | 音频数据大小 |
| dataSize
<sup>
9+
</sup>
| number | 应用总数据大小 |
| video | number | 视频数据大小 |
\ No newline at end of file
| image | number | 图像数据大小 |
| file | number | 文件数据大小 |
| app | number | 应用数据大小 |
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录