From 7831ae6380a192b30e62fbf18426b1e9b1ede0e8 Mon Sep 17 00:00:00 2001 From: zengyawen Date: Fri, 28 Apr 2023 11:58:26 +0800 Subject: [PATCH] update docs Signed-off-by: zengyawen --- .../apis/js-apis-file-environment.md | 42 +- .../reference/apis/js-apis-file-fileuri.md | 10 +- .../reference/apis/js-apis-file-fs.md | 433 ++++++++-- .../reference/apis/js-apis-file-hash.md | 21 +- .../reference/apis/js-apis-file-picker.md | 37 +- .../apis/js-apis-file-securityLabel.md | 93 ++- .../reference/apis/js-apis-file-statvfs.md | 20 +- .../apis/js-apis-file-storage-statistics.md | 240 +++++- .../apis/js-apis-file-volumemanager.md | 228 +++++- .../reference/apis/js-apis-fileAccess.md | 773 +++++++++++------- .../reference/apis/js-apis-fileShare.md | 43 +- .../reference/apis/js-apis-userFileManager.md | 73 +- .../errorcodes/errorcode-filemanagement.md | 40 +- 13 files changed, 1559 insertions(+), 494 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-file-environment.md b/zh-cn/application-dev/reference/apis/js-apis-file-environment.md index c7d9fd584a..7d79a95711 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-file-environment.md +++ b/zh-cn/application-dev/reference/apis/js-apis-file-environment.md @@ -3,9 +3,9 @@ 该模块提供环境目录能力,获取内存存储根目录、公共文件根目录的JS接口。 > **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 -> 本模块接口为系统接口,三方应用不支持调用。 -> 本模块支持对错误码进行处理,错误码及其适配方式[参考文档](../errorcodes/errorcode-filemanagement.md#错误码适配指导)。 +> +> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +> - 本模块接口为系统接口,三方应用不支持调用。 ## 导入模块 @@ -27,6 +27,15 @@ getStorageDataDir():Promise<string> | --------------------- | ---------------- | | Promise<string> | 返回存储根目录 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)。 +| 错误码ID | 错误信息 | +| ---------------------------- | ---------- | +| 202 | The caller is not a system application | +| 13900020 | Invalid argument | +| 13900042 | Unknown error | + **示例:** ```js @@ -51,6 +60,15 @@ getStorageDataDir(callback:AsyncCallback<string>):void | -------- | --------------------------- | ---- | -------------------------------- | | callback | AsyncCallback<string> | 是 | 异步获取内存存储根目录之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)。 +| 错误码ID | 错误信息 | +| ---------------------------- | ---------- | +| 202 | The caller is not a system application | +| 13900020 | Invalid argument | +| 13900042 | Unknown error | + **示例:** ```js @@ -77,6 +95,15 @@ getUserDataDir():Promise<string> | --------------------- | ------------------ | | Promise<string> | 返回公共文件根目录 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)。 +| 错误码ID | 错误信息 | +| ---------------------------- | ---------- | +| 202 | The caller is not a system application | +| 13900020 | Invalid argument | +| 13900042 | Unknown error | + **示例:** ```js @@ -101,6 +128,15 @@ getUserDataDir(callback:AsyncCallback<string>): void | -------- | --------------------------- | ---- | -------------------------------- | | callback | AsyncCallback<string> | 是 | 异步获取公共文件根目录之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)。 +| 错误码ID | 错误信息 | +| ---------------------------- | ---------- | +| 202 | The caller is not a system application | +| 13900020 | Invalid argument | +| 13900042 | Unknown error | + **示例:** ```js diff --git a/zh-cn/application-dev/reference/apis/js-apis-file-fileuri.md b/zh-cn/application-dev/reference/apis/js-apis-file-fileuri.md index acf1eb72d5..23949ae317 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-file-fileuri.md +++ b/zh-cn/application-dev/reference/apis/js-apis-file-fileuri.md @@ -3,6 +3,7 @@ 该模块提供通过PATH获取文件统一资源标志符(Uniform Resource Identifier,URI),后续可通过使用[@ohos.file.fs](js-apis-file-fs.md)进行相关open、read、write等操作,实现文件分享。 > **说明:** +> > - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 ## 导入模块 @@ -46,11 +47,10 @@ getUriFromPath(path: string): string **错误码:** -以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md#错误码适配指导) - | 错误码ID | 错误信息 | - | ---------------------------- | ---------- | - | 401 | The input parameter is invalid | - +以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)。 +| 错误码ID | 错误信息 | +| ---------------------------- | ---------- | +| 401 | The input parameter is invalid | **示例:** diff --git a/zh-cn/application-dev/reference/apis/js-apis-file-fs.md b/zh-cn/application-dev/reference/apis/js-apis-file-fs.md index ecd961bcb7..4ea3833751 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-file-fs.md +++ b/zh-cn/application-dev/reference/apis/js-apis-file-fs.md @@ -3,6 +3,7 @@ 该模块为基础文件操作API,提供基础文件操作能力,包括文件基本管理、文件目录管理、文件信息统计、文件流式读写等常用功能。 > **说明:** +> > 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 ## 导入模块 @@ -11,10 +12,6 @@ import fs from '@ohos.file.fs'; ``` -## 错误码说明 - -本模块支持对错误码进行处理,错误码及其适配方式请参考文档:[文件管理错误码](../errorcodes/errorcode-filemanagement.md#错误码适配指导)。 - ## 使用说明 使用该功能模块对文件/目录进行操作前,需要先获取其应用沙箱路径,获取方式及其接口用法请参考: @@ -65,6 +62,10 @@ stat(file: string|number): Promise<Stat> | ---------------------------- | ---------- | | Promise<[Stat](#stat)> | Promise对象。返回文件的具体信息。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -91,6 +92,10 @@ stat(file: string|number, callback: AsyncCallback<Stat>): void | file | string\|number | 是 | 文件应用沙箱路径path或已打开的文件描述符fd。 | | callback | AsyncCallback<[Stat](#stat)> | 是 | 异步获取文件的信息之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -117,13 +122,16 @@ statSync(file: string|number): Stat | ------ | ------ | ---- | -------------------------- | | file | string\|number | 是 | 文件应用沙箱路径path或已打开的文件描述符fd。 | - **返回值:** | 类型 | 说明 | | ------------- | ---------- | | [Stat](#stat) | 表示文件的具体信息。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -151,6 +159,10 @@ access(path: string): Promise<boolean> | ------------------- | ---------------------------- | | Promise<boolean> | Promise对象。返回boolean,表示文件是否存在。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -164,7 +176,6 @@ access(path: string): Promise<boolean> }); ``` - ## fs.access access(path: string, callback: AsyncCallback<boolean>): void @@ -178,7 +189,11 @@ access(path: string, callback: AsyncCallback<boolean>): void | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ------------------------------------------------------------ | | path | string | 是 | 文件应用沙箱路径。 | -| callback | AsyncCallback<boolean> | 是 | 异步检查文件是否存在的回调。 | +| callback | AsyncCallback<boolean> | 是 | 异步检查文件是否存在的回调,如果存在,回调返回true,否则返回false。 | + +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 **示例:** @@ -213,7 +228,11 @@ accessSync(path: string): boolean | 类型 | 说明 | | ------------------- | ---------------------------- | - | boolean | 返回boolean,表示文件是否存在。 | + | boolean | 返回true,表示文件存在;返回false,表示文件不存在。 | + +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 **示例:** @@ -250,6 +269,10 @@ close(file: File|number): Promise<void> | ------------------- | ---------------------------- | | Promise<void> | Promise对象。无返回值。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -278,6 +301,10 @@ close(file: File|number, callback: AsyncCallback<void>): void | file | [File](#file)\|number | 是 | 已打开的File对象或已打开的文件描述符fd。 | | callback | AsyncCallback<void> | 是 | 异步关闭文件之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -306,6 +333,10 @@ closeSync(file: File|number): void | ---- | ------ | ---- | ------------ | | file | [File](#file)\|number | 是 | 已打开的File对象或已打开的文件描述符fd。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -336,6 +367,10 @@ copyFile(src: string|number, dest: string|number, mode?: number): Promise<voi | ------------------- | ---------------------------- | | Promise<void> | Promise对象。无返回值。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -365,6 +400,10 @@ copyFile(src: string|number, dest: string|number, mode?: number, callback: Async | mode | number | 否 | mode提供覆盖文件的选项,当前仅支持0,且默认为0。
0:完全覆盖目标文件,未覆盖部分将被裁切掉。 | | callback | AsyncCallback<void> | 是 | 异步复制文件之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -396,6 +435,10 @@ copyFileSync(src: string|number, dest: string|number, mode?: number): void | dest | string\|number | 是 | 目标文件路径或目标文件的文件描述符。 | | mode | number | 否 | mode提供覆盖文件的选项,当前仅支持0,且默认为0。
0:完全覆盖目标文件,未覆盖部分将被裁切掉。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -404,7 +447,6 @@ copyFileSync(src: string|number, dest: string|number, mode?: number): void fs.copyFileSync(srcPath, dstPath); ``` - ## fs.mkdir mkdir(path: string): Promise<void> @@ -425,6 +467,10 @@ mkdir(path: string): Promise<void> | ------------------- | ---------------------------- | | Promise<void> | Promise对象。无返回值。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -436,7 +482,6 @@ mkdir(path: string): Promise<void> }); ``` - ## fs.mkdir mkdir(path: string, callback: AsyncCallback<void>): void @@ -452,6 +497,10 @@ mkdir(path: string, callback: AsyncCallback<void>): void | path | string | 是 | 目录的应用沙箱路径。 | | callback | AsyncCallback<void> | 是 | 异步创建目录操作完成之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -465,7 +514,6 @@ mkdir(path: string, callback: AsyncCallback<void>): void }); ``` - ## fs.mkdirSync mkdirSync(path: string): void @@ -480,6 +528,10 @@ mkdirSync(path: string): void | ------ | ------ | ---- | ------------------------------------------------------------ | | path | string | 是 | 目录的应用沙箱路径。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -487,7 +539,6 @@ mkdirSync(path: string): void fs.mkdirSync(dirPath); ``` - ## fs.open open(path: string, mode?: number): Promise<File> @@ -509,6 +560,10 @@ open(path: string, mode?: number): Promise<File> | --------------------- | ----------- | | Promise<[File](#file)> | Promise对象。返回File对象。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -536,6 +591,10 @@ open(path: string, mode?: number, callback: AsyncCallback<File>): void | path | string | 是 | 文件的应用沙箱路径或URI。 | | mode | number | 否 | 打开文件的[选项](#openmode),必须指定如下选项中的一个,默认以只读方式打开:
- OpenMode.READ_ONLY(0o0):只读打开。
- OpenMode.WRITE_ONLY(0o1):只写打开。
- OpenMode.READ_WRITE(0o2):读写打开。
给定如下功能选项,以按位或的方式追加,默认不给定任何额外选项:
- OpenMode.CREATE(0o100):若文件不存在,则创建文件。
- OpenMode.TRUNC(0o1000):如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。
- OpenMode.APPEND(0o2000):以追加方式打开,后续写将追加到文件末尾。
- OpenMode.NONBLOCK(0o4000):如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续 IO 进行非阻塞操作。
- OpenMode.DIR(0o200000):如果path不指向目录,则出错。
- OpenMode.NOFOLLOW(0o400000):如果path指向符号链接,则出错。
- OpenMode.SYNC(0o4010000):以同步IO的方式打开文件。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -570,6 +629,10 @@ openSync(path: string, mode?: number): File | ------ | ----------- | | [File](#file) | 打开的File对象。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -601,6 +664,10 @@ read(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: numb | ---------------------------------- | ------ | | Promise<number> | Promise对象。返回读取的结果。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -633,6 +700,10 @@ read(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: numb | options | Object | 否 | 支持如下选项:
- offset,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度。| | callback | AsyncCallback<number> | 是 | 异步读取数据之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -650,7 +721,6 @@ read(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: numb }); ``` - ## fs.readSync readSync(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): number @@ -673,6 +743,10 @@ readSync(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: | ------ | -------- | | number | 实际读取的长度。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -683,7 +757,6 @@ readSync(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: fs.closeSync(file); ``` - ## fs.rmdir rmdir(path: string): Promise<void> @@ -704,6 +777,10 @@ rmdir(path: string): Promise<void> | ------------------- | ---------------------------- | | Promise<void> | Promise对象。无返回值。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -715,7 +792,6 @@ rmdir(path: string): Promise<void> }); ``` - ## fs.rmdir rmdir(path: string, callback: AsyncCallback<void>): void @@ -731,6 +807,10 @@ rmdir(path: string, callback: AsyncCallback<void>): void | path | string | 是 | 目录的应用沙箱路径。 | | callback | AsyncCallback<void> | 是 | 异步删除目录之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -744,7 +824,6 @@ rmdir(path: string, callback: AsyncCallback<void>): void }); ``` - ## fs.rmdirSync rmdirSync(path: string): void @@ -759,6 +838,10 @@ rmdirSync(path: string): void | ------ | ------ | ---- | -------------------------- | | path | string | 是 | 目录的应用沙箱路径。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -766,7 +849,6 @@ rmdirSync(path: string): void fs.rmdirSync(dirPath); ``` - ## fs.unlink unlink(path: string): Promise<void> @@ -787,6 +869,10 @@ unlink(path: string): Promise<void> | ------------------- | ---------------------------- | | Promise<void> | Promise对象。无返回值。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -798,7 +884,6 @@ unlink(path: string): Promise<void> }); ``` - ## fs.unlink unlink(path: string, callback: AsyncCallback<void>): void @@ -814,6 +899,10 @@ unlink(path: string, callback: AsyncCallback<void>): void | path | string | 是 | 文件的应用沙箱路径。 | | callback | AsyncCallback<void> | 是 | 异步删除文件之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -827,7 +916,6 @@ unlink(path: string, callback: AsyncCallback<void>): void }); ``` - ## fs.unlinkSync unlinkSync(path: string): void @@ -842,6 +930,10 @@ unlinkSync(path: string): void | ------ | ------ | ---- | -------------------------- | | path | string | 是 | 文件的应用沙箱路径。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -872,6 +964,10 @@ write(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; lengt | --------------------- | -------- | | Promise<number> | Promise对象。返回实际写入的长度。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -885,7 +981,6 @@ write(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; lengt }); ``` - ## fs.write write(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }, callback: AsyncCallback<number>): void @@ -903,6 +998,10 @@ write(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; lengt | options | Object | 否 | 支持如下选项:
- offset,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。
- length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度。
- encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认 'utf-8'。当前仅支持 'utf-8'。| | callback | AsyncCallback<number> | 是 | 异步将数据写入完成后执行的回调函数。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -918,7 +1017,6 @@ write(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; lengt }); ``` - ## fs.writeSync writeSync(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }): number @@ -941,6 +1039,10 @@ writeSync(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; l | ------ | -------- | | number | 实际写入的长度。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -972,6 +1074,10 @@ truncate(file: string|number, len?: number): Promise<void> | ------------------- | ---------------------------- | | Promise<void> | Promise对象。无返回值。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -984,7 +1090,6 @@ truncate(file: string|number, len?: number): Promise<void> }); ``` - ## fs.truncate truncate(file: string|number, len?: number, callback: AsyncCallback<void>): void @@ -1001,6 +1106,10 @@ truncate(file: string|number, len?: number, callback: AsyncCallback<void>) | len | number | 否 | 文件截断后的长度,以字节为单位。默认为0。 | | callback | AsyncCallback<void> | 是 | 回调函数,本调用无返回值。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1015,7 +1124,6 @@ truncate(file: string|number, len?: number, callback: AsyncCallback<void>) }); ``` - ## fs.truncateSync truncateSync(file: string|number, len?: number): void @@ -1031,6 +1139,10 @@ truncateSync(file: string|number, len?: number): void | file | string\|number | 是 | 文件的应用沙箱路径或已打开的文件描述符fd。 | | len | number | 否 | 文件截断后的长度,以字节为单位。默认为0。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1039,7 +1151,6 @@ truncateSync(file: string|number, len?: number): void fs.truncateSync(filePath, len); ``` - ## fs.readText readText(filePath: string, options?: { offset?: number; length?: number; encoding?: string; }): Promise<string> @@ -1061,6 +1172,10 @@ readText(filePath: string, options?: { offset?: number; length?: number; encodin | --------------------- | ---------- | | Promise<string> | Promise对象。返回读取文件的内容。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1072,7 +1187,6 @@ readText(filePath: string, options?: { offset?: number; length?: number; encodin }); ``` - ## fs.readText readText(filePath: string, options?: { offset?: number; length?: number; encoding?: string; }, callback: AsyncCallback<string>): void @@ -1089,6 +1203,10 @@ readText(filePath: string, options?: { offset?: number; length?: number; encodin | options | Object | 否 | 支持如下选项:
- offset,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读取。
- length,number类型,表示期望读取数据的长度。可选,默认文件长度。
- encoding,string类型,表示数据的编码方式,默认 'utf-8',仅支持 'utf-8'。 | | callback | AsyncCallback<string> | 是 | 回调函数,返回读取文件的内容。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1102,7 +1220,6 @@ readText(filePath: string, options?: { offset?: number; length?: number; encodin }); ``` - ## fs.readTextSync readTextSync(filePath: string, options?: { offset?: number; length?: number; encoding?: string; }): string @@ -1124,6 +1241,10 @@ readTextSync(filePath: string, options?: { offset?: number; length?: number; enc | ------ | -------------------- | | string | 返回读取文件的内容。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1152,6 +1273,10 @@ lstat(path: string): Promise<Stat> | ---------------------------- | ---------- | | Promise<[Stat](#stat)> | promise对象,返回文件对象,表示文件的具体信息,详情见stat。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1163,7 +1288,6 @@ lstat(path: string): Promise<Stat> }); ``` - ## fs.lstat lstat(path: string, callback: AsyncCallback<Stat>): void @@ -1179,6 +1303,10 @@ lstat(path: string, callback: AsyncCallback<Stat>): void | path | string | 是 | 文件的应用沙箱路径。 | | callback | AsyncCallback<[Stat](#stat)> | 是 | 回调函数,返回文件的具体信息。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1212,6 +1340,10 @@ lstatSync(path: string): Stat | ------------- | ---------- | | [Stat](#stat) | 表示文件的具体信息。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1240,6 +1372,10 @@ rename(oldPath: string, newPath: string): Promise<void> | ------------------- | ---------------------------- | | Promise<void> | Promise对象。无返回值。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1268,6 +1404,10 @@ rename(oldPath: string, newPath: string, callback: AsyncCallback<void>): v | newPath | string | 是 | 文件的应用沙箱新路径。 | | callback | AsyncCallback<void> | 是 | 异步重命名文件之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1297,6 +1437,10 @@ renameSync(oldPath: string, newPath: string): void | oldPath | string | 是 | 文件的应用沙箱原路径。 | | newPath | string | 是 | 文件的应用沙箱新路径。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1305,7 +1449,6 @@ renameSync(oldPath: string, newPath: string): void fs.renameSync(srcFile, dstFile); ``` - ## fs.fsync fsync(fd: number): Promise<void> @@ -1326,6 +1469,10 @@ fsync(fd: number): Promise<void> | ------------------- | ---------------------------- | | Promise<void> | Promise对象。无返回值。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1338,7 +1485,6 @@ fsync(fd: number): Promise<void> }); ``` - ## fs.fsync fsync(fd: number, callback: AsyncCallback<void>): void @@ -1354,6 +1500,10 @@ fsync(fd: number, callback: AsyncCallback<void>): void | fd | number | 是 | 已打开的文件描述符。 | | Callback | AsyncCallback<void> | 是 | 异步将文件数据同步之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1384,6 +1534,10 @@ fsyncSync(fd: number): void | ---- | ------ | ---- | ------------ | | fd | number | 是 | 已打开的文件描述符。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1393,7 +1547,6 @@ fsyncSync(fd: number): void fs.closeSync(file); ``` - ## fs.fdatasync fdatasync(fd: number): Promise<void> @@ -1414,6 +1567,10 @@ fdatasync(fd: number): Promise<void> | ------------------- | ---------------------------- | | Promise<void> | Promise对象。无返回值。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1427,7 +1584,6 @@ fdatasync(fd: number): Promise<void> }); ``` - ## fs.fdatasync fdatasync(fd: number, callback: AsyncCallback<void>): void @@ -1443,6 +1599,10 @@ fdatasync(fd: number, callback: AsyncCallback<void>): void | fd | number | 是 | 已打开的文件描述符。 | | callback | AsyncCallback<void> | 是 | 异步将文件内容数据同步之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1472,6 +1632,10 @@ fdatasyncSync(fd: number): void | ---- | ------ | ---- | ------------ | | fd | number | 是 | 已打开的文件描述符。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1481,7 +1645,6 @@ fdatasyncSync(fd: number): void fs.closeSync(file); ``` - ## fs.symlink symlink(target: string, srcPath: string): Promise<void> @@ -1503,6 +1666,10 @@ symlink(target: string, srcPath: string): Promise<void> | ------------------- | ---------------------------- | | Promise<void> | Promise对象。无返回值。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1531,6 +1698,10 @@ symlink(target: string, srcPath: string, callback: AsyncCallback<void>): v | srcPath | string | 是 | 符号链接文件的应用沙箱路径。 | | callback | AsyncCallback<void> | 是 | 异步创建符号链接信息之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1560,6 +1731,10 @@ symlinkSync(target: string, srcPath: string): void | target | string | 是 | 源文件的应用沙箱路径。 | | srcPath | string | 是 | 符号链接文件的应用沙箱路径。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1573,7 +1748,7 @@ listFile(path: string, options?: { recursion?: boolean; listNum?: number; filter?: Filter; -}): Promise; +}): Promise 列出文件夹下所有文件名,支持递归列出所有文件名(包含子目录下),支持文件过滤,使用Promise异步回调。 @@ -1600,6 +1775,10 @@ listFile(path: string, options?: { | --------------------- | ---------- | | Promise<string[]> | Promise对象。返回文件名数组。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1628,7 +1807,7 @@ listFile(path: string, options?: { recursion?: boolean; listNum?: number; filter?: Filter; -}, callback: AsyncCallback): void; +}, callback: AsyncCallback): void 列出文件夹下所有文件名,支持递归列出所有文件名(包含子目录下),支持文件过滤,使用Callback异步回调。 @@ -1648,6 +1827,10 @@ listFile(path: string, options?: { | listNum | number | 否 | 列出文件名数量。当设置0时,列出所有文件,默认为0。 | | filter | [Filter](#filter) | 否 | 文件过滤选项。当前仅支持后缀名匹配、文件名模糊查询、文件大小过滤、最近修改时间过滤。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1679,7 +1862,7 @@ listFileSync(path: string, options?: { recursion?: boolean; listNum?: number; filter?: Filter; -}): string[]; +}): string[] 以同步方式列出文件夹下所有文件名,支持递归列出所有文件名(包含子目录下),支持文件过滤。 @@ -1704,6 +1887,10 @@ listFileSync(path: string, options?: { | --------------------- | ---------- | | string[] | 返回文件名数组。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1723,9 +1910,10 @@ listFileSync(path: string, options?: { console.info("filename: %s", filenames[i]); } ``` + ## fs.moveFile -moveFile(src: string, dest: string, mode?: number): Promise\; +moveFile(src: string, dest: string, mode?: number): Promise\ 移动文件,使用Promise异步回调。 @@ -1739,6 +1927,16 @@ moveFile(src: string, dest: string, mode?: number): Promise\; | dest | string | 是 | 目的文件的应用沙箱路径。 | | mode | number | 否 | 移动模式。若mode为0,移动位置存在同名文件时,强制移动覆盖。若mode为1,移动位置存在同名文件时,抛出异常。默认为0。 | +**返回值:** + + | 类型 | 说明 | + | ------------------- | ---------------------------- | + | Promise<void> | Promise对象。无返回值。 | + +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1753,7 +1951,7 @@ moveFile(src: string, dest: string, mode?: number): Promise\; ## fs.moveFile -moveFile(src: string, dest: string, mode?: number, callback: AsyncCallback\): void; +moveFile(src: string, dest: string, mode?: number, callback: AsyncCallback\): void 移动文件,使用Callback异步回调。 @@ -1768,6 +1966,10 @@ moveFile(src: string, dest: string, mode?: number, callback: AsyncCallback\- r+:打开可读写的文件,该文件必须存在。
- w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。
- a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 | | callback | AsyncCallback<[Stream](#stream)> | 是 | 异步打开文件流之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -1974,6 +2199,10 @@ createStreamSync(path: string, mode: string): Stream | ------------------ | --------- | | [Stream](#stream) | 返回文件流的结果。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2003,6 +2232,10 @@ fdopenStream(fd: number, mode: string): Promise<Stream> | --------------------------------- | --------- | | Promise<[Stream](#stream)> | Promise对象。返回文件流的结果。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2016,7 +2249,6 @@ fdopenStream(fd: number, mode: string): Promise<Stream> }); ``` - ## fs.fdopenStream fdopenStream(fd: number, mode: string, callback: AsyncCallback<Stream>): void @@ -2033,6 +2265,10 @@ fdopenStream(fd: number, mode: string, callback: AsyncCallback<Stream>): v | mode | string | 是 | - r:打开只读文件,该文件必须存在。
- r+:打开可读写的文件,该文件必须存在。
- w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。
- a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 | | callback | AsyncCallback<[Stream](#stream)> | 是 | 异步打开文件流之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2069,6 +2305,10 @@ fdopenStreamSync(fd: number, mode: string): Stream | ------------------ | --------- | | [Stream](#stream) | 返回文件流的结果。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2082,7 +2322,7 @@ fdopenStreamSync(fd: number, mode: string): Stream 文件具体信息,在调用Stat的方法前,需要先通过[stat()](#fsstat)方法(同步或异步)来构建一个Stat实例。 -**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.File.FileIO。 +**系统能力**:SystemCapability.FileManagement.File.FileIO ### 属性 @@ -2097,7 +2337,6 @@ fdopenStreamSync(fd: number, mode: string): Stream | mtime | number | 是 | 否 | 上次修改该文件的时间,表示距1970年1月1日0时0分0秒的秒数。 | | ctime | number | 是 | 否 | 最近改变文件状态的时间,表示距1970年1月1日0时0分0秒的秒数。 | - ### isBlockDevice isBlockDevice(): boolean @@ -2112,6 +2351,10 @@ isBlockDevice(): boolean | ------- | ---------------- | | boolean | 表示文件是否是块特殊设备。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2133,6 +2376,10 @@ isCharacterDevice(): boolean | ------- | ----------------- | | boolean | 表示文件是否是字符特殊设备。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2140,7 +2387,6 @@ isCharacterDevice(): boolean let isCharacterDevice = fs.statSync(filePath).isCharacterDevice(); ``` - ### isDirectory isDirectory(): boolean @@ -2155,6 +2401,10 @@ isDirectory(): boolean | ------- | ------------- | | boolean | 表示文件是否是目录。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2162,7 +2412,6 @@ isDirectory(): boolean let isDirectory = fs.statSync(dirPath).isDirectory(); ``` - ### isFIFO isFIFO(): boolean @@ -2177,6 +2426,10 @@ isFIFO(): boolean | ------- | --------------------- | | boolean | 表示文件是否是 FIFO。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2184,7 +2437,6 @@ isFIFO(): boolean let isFIFO = fs.statSync(filePath).isFIFO(); ``` - ### isFile isFile(): boolean @@ -2199,6 +2451,10 @@ isFile(): boolean | ------- | --------------- | | boolean | 表示文件是否是普通文件。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2206,7 +2462,6 @@ isFile(): boolean let isFile = fs.statSync(filePath).isFile(); ``` - ### isSocket isSocket(): boolean @@ -2221,6 +2476,10 @@ isSocket(): boolean | ------- | -------------- | | boolean | 表示文件是否是套接字。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2228,7 +2487,6 @@ isSocket(): boolean let isSocket = fs.statSync(filePath).isSocket(); ``` - ### isSymbolicLink isSymbolicLink(): boolean @@ -2243,6 +2501,10 @@ isSymbolicLink(): boolean | ------- | --------------- | | boolean | 表示文件是否是符号链接。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2254,7 +2516,6 @@ isSymbolicLink(): boolean 文件流,在调用Stream的方法前,需要先通过createStream()方法(同步或异步)来构建一个Stream实例。 - ### close close(): Promise<void> @@ -2269,6 +2530,10 @@ close(): Promise<void> | ------------------- | ------------- | | Promise<void> | Promise对象。返回表示异步关闭文件流的结果。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2281,7 +2546,6 @@ close(): Promise<void> }); ``` - ### close close(callback: AsyncCallback<void>): void @@ -2296,6 +2560,10 @@ close(callback: AsyncCallback<void>): void | -------- | ------------------------- | ---- | ------------- | | callback | AsyncCallback<void> | 是 | 异步关闭文件流之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2318,6 +2586,10 @@ closeSync(): void **系统能力**:SystemCapability.FileManagement.File.FileIO +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2340,6 +2612,10 @@ flush(): Promise<void> | ------------------- | ------------- | | Promise<void> | Promise对象。返回表示异步刷新文件流的结果。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2352,7 +2628,6 @@ flush(): Promise<void> }); ``` - ### flush flush(callback: AsyncCallback<void>): void @@ -2367,6 +2642,10 @@ flush(callback: AsyncCallback<void>): void | -------- | ------------------------- | ---- | -------------- | | callback | AsyncCallback<void> | 是 | 异步刷新文件流后的回调函数。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2389,6 +2668,10 @@ flushSync(): void **系统能力**:SystemCapability.FileManagement.File.FileIO +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2418,6 +2701,10 @@ write(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; | --------------------- | -------- | | Promise<number> | Promise对象。返回实际写入的长度。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2430,7 +2717,6 @@ write(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; }); ``` - ### write write(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }, callback: AsyncCallback<number>): void @@ -2447,6 +2733,10 @@ write(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; | options | Object | 否 | 支持如下选项:
- length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度。
- offset,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。
- encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认 'utf-8'。仅支持 'utf-8'。| | callback | AsyncCallback<number> | 是 | 异步写入完成后执行的回调函数。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2484,6 +2774,10 @@ writeSync(buffer: ArrayBuffer|string, options?: { offset?: number; length?: numb | ------ | -------- | | number | 实际写入的长度。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2513,6 +2807,10 @@ read(buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): Prom | ---------------------------------- | ------ | | Promise<number> | Promise对象。返回读取的结果。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2527,7 +2825,6 @@ read(buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): Prom }); ``` - ### read read(buffer: ArrayBuffer, options?: { position?: number; offset?: number; length?: number; }, callback: AsyncCallback<number>): void @@ -2544,6 +2841,10 @@ read(buffer: ArrayBuffer, options?: { position?: number; offset?: number; length | options | Object | 否 | 支持如下选项:
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度。
- offset,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读. | | callback | AsyncCallback<number> | 是 | 异步从流文件读取数据之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2581,6 +2882,10 @@ readSync(buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): | ------ | -------- | | number | 实际读取的长度。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2603,7 +2908,7 @@ readSync(buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): ### lock -lock(exclusive?: boolean): Promise\; +lock(exclusive?: boolean): Promise\ 文件阻塞式施加共享锁或独占锁,使用Promise异步回调。 @@ -2621,6 +2926,10 @@ lock(exclusive?: boolean): Promise\; | ---------------------------------- | ------ | | Promise<void> | Promise对象。无返回值。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2634,7 +2943,7 @@ lock(exclusive?: boolean): Promise\; ### lock -lock(exclusive?: boolean, callback: AsyncCallback\): void; +lock(exclusive?: boolean, callback: AsyncCallback\): void 文件阻塞式施加共享锁或独占锁,使Callback异步回调。 @@ -2647,6 +2956,10 @@ lock(exclusive?: boolean, callback: AsyncCallback\): void; | exclusive | boolean | 否 | 是否施加独占锁,默认false。 | | callback | AsyncCallback<void> | 是 | 异步文件上锁之后的回调。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2662,7 +2975,7 @@ lock(exclusive?: boolean, callback: AsyncCallback\): void; ### tryLock -tryLock(exclusive?: boolean): void; +tryLock(exclusive?: boolean): void 文件非阻塞式施加共享锁或独占锁。 @@ -2674,6 +2987,10 @@ tryLock(exclusive?: boolean): void; | ------- | ----------- | ---- | ---------------------------------------- | | exclusive | boolean | 否 | 是否施加独占锁,默认false。 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -2684,12 +3001,16 @@ tryLock(exclusive?: boolean): void; ### unlock -unlock(): void; +unlock(): void 以同步方式给文件解锁。 **系统能力**:SystemCapability.FileManagement.File.FileIO +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js diff --git a/zh-cn/application-dev/reference/apis/js-apis-file-hash.md b/zh-cn/application-dev/reference/apis/js-apis-file-hash.md index 911dac45c0..ce294a6ee9 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-file-hash.md +++ b/zh-cn/application-dev/reference/apis/js-apis-file-hash.md @@ -3,8 +3,8 @@ 该模块提供文件哈希处理能力,对文件内容进行哈希处理。 > **说明:** +> > 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 -> 本模块支持对错误码进行处理,错误码及其适配方式[参考文档](../errorcodes/errorcode-filemanagement.md#错误码适配指导)。 ## 导入模块 @@ -63,6 +63,15 @@ hash(path: string, algorithm: string): Promise<string> | --------------------- | -------------------------- | | Promise<string> | Promise对象。返回文件的哈希值。表示为十六进制数字串,所有字母均大写。 | +**错误码:** + +以下错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 13900020 | Invalid argument | +| 13900042 | Unknown error | + **示例:** ```js @@ -90,7 +99,17 @@ hash(path: string, algorithm: string, callback: AsyncCallback<string>): vo | algorithm | string | 是 | 哈希计算采用的算法。可选 "md5"、"sha1" 或 "sha256"。建议采用安全强度更高的 "sha256"。 | | callback | AsyncCallback<string> | 是 | 异步计算文件哈希操作之后的回调函数(其中给定文件哈希值表示为十六进制数字串,所有字母均大写)。 | +**错误码:** + +以下错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 13900020 | Invalid argument | +| 13900042 | Unknown error | + **示例:** + ```js let filePath = pathDir + "/test.txt"; Hash.hash(filePath, "sha256", (err, str) => { diff --git a/zh-cn/application-dev/reference/apis/js-apis-file-picker.md b/zh-cn/application-dev/reference/apis/js-apis-file-picker.md index 1455a81789..44e8bae028 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-file-picker.md +++ b/zh-cn/application-dev/reference/apis/js-apis-file-picker.md @@ -6,6 +6,7 @@ 选择器(Picker)是一个封装PhotoViewPicker、DocumentViewPicker、AudioViewPicker等系统应用选择与保存能力的模块。应用可以自行选择使用哪种picker实现文件选择和文件保存的功能。 ## 导入模块 + ```js import picker from '@ohos.file.picker'; ``` @@ -30,7 +31,7 @@ select(option?: PhotoSelectOptions) : Promise<PhotoSelectResult> **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -70,7 +71,7 @@ select(option: PhotoSelectOptions, callback: AsyncCallback<PhotoSelectResult& **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -107,7 +108,7 @@ select(callback: AsyncCallback<PhotoSelectResult>) : void **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -140,7 +141,7 @@ save(option?: PhotoSaveOptions) : Promise<Array<string>> **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -179,7 +180,7 @@ save(option: PhotoSaveOptions, callback: AsyncCallback<Array<string>> **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -215,7 +216,7 @@ save(callback: AsyncCallback<Array<string>>) : void **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -260,7 +261,7 @@ select(option?: DocumentSelectOptions) : Promise<Array<string>> **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -298,7 +299,7 @@ select(option: DocumentSelectOptions, callback: AsyncCallback<Array<string **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -333,7 +334,7 @@ select(callback: AsyncCallback<Array<string>>) : void **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -367,7 +368,7 @@ save(option?: DocumentSaveOptions) : Promise<Array<string>> **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -406,7 +407,7 @@ save(option: DocumentSaveOptions, callback: AsyncCallback<Array<string> **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -442,7 +443,7 @@ save(callback: AsyncCallback<Array<string>>) : void **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -487,7 +488,7 @@ select(option?: AudioSelectOptions) : Promise<Array<string>> **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -525,7 +526,7 @@ select(option: AudioSelectOptions, callback: AsyncCallback<Array<string> **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -560,7 +561,7 @@ select(callback: AsyncCallback<Array<string>>) : void **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -593,7 +594,7 @@ save(option?: AudioSaveOptions) : Promise<Array<string>> **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -632,7 +633,7 @@ save(option: AudioSaveOptions, callback: AsyncCallback<Array<string>> **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -668,7 +669,7 @@ save(callback: AsyncCallback<Array<string>>) : void **系统能力**:SystemCapability.FileManagement.UserFileService -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | diff --git a/zh-cn/application-dev/reference/apis/js-apis-file-securityLabel.md b/zh-cn/application-dev/reference/apis/js-apis-file-securityLabel.md index d7110ee4df..9a898d04d4 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-file-securityLabel.md +++ b/zh-cn/application-dev/reference/apis/js-apis-file-securityLabel.md @@ -3,8 +3,8 @@ 该模块提供文件数据安全等级的相关功能:向应用程序提供查询、设置文件数据安全等级的JS接口。 > **说明:** +> > 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 -> 本模块支持对错误码进行处理,错误码及其适配方式[参考文档](../errorcodes/errorcode-filemanagement.md#错误码适配指导)。 ## 导入模块 @@ -63,6 +63,21 @@ setSecurityLabel(path:string, type:DataLevel):Promise<void> | ------------------- | ---------------- | | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。| +**错误码:** + +以下错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 13900001 | Operation not permitted | +| 13900007 | Arg list too long | +| 13900015 | File exists | +| 13900020 | Invalid argument | +| 13900025 | No space left on device | +| 13900037 | No data available | +| 13900041 | Quota exceeded | +| 13900042 | Unknown error | + **示例:** ```js @@ -90,6 +105,21 @@ setSecurityLabel(path:string, type:DataLevel, callback: AsyncCallback<void> | type | DataLevel | 是 | 文件等级属性,只支持"s0","s1","s2","s3","s4" | | callback | AsyncCallback<void> | 是 | 是否设置数据标签之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 13900001 | Operation not permitted | +| 13900007 | Arg list too long | +| 13900015 | File exists | +| 13900020 | Invalid argument | +| 13900025 | No space left on device | +| 13900037 | No data available | +| 13900041 | Quota exceeded | +| 13900042 | Unknown error | + **示例:** ```js @@ -118,6 +148,21 @@ setSecurityLabelSync(path:string, type:DataLevel):void | path | string | 是 | 文件路径 | | type | DataLevel | 是 | 文件等级属性,只支持"s0","s1","s2","s3","s4" | +**错误码:** + +以下错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 13900001 | Operation not permitted | +| 13900007 | Arg list too long | +| 13900015 | File exists | +| 13900020 | Invalid argument | +| 13900025 | No space left on device | +| 13900037 | No data available | +| 13900041 | Quota exceeded | +| 13900042 | Unknown error | + **示例:** ```js @@ -145,6 +190,21 @@ getSecurityLabel(path:string):Promise<string> | --------------------- | ------------ | | Promise<string> | 返回数据标签 | +**错误码:** + +以下错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 13900001 | Operation not permitted | +| 13900007 | Arg list too long | +| 13900015 | File exists | +| 13900020 | Invalid argument | +| 13900025 | No space left on device | +| 13900037 | No data available | +| 13900041 | Quota exceeded | +| 13900042 | Unknown error | + **示例:** ```js @@ -171,6 +231,21 @@ getSecurityLabel(path:string, callback:AsyncCallback<string>): void | path | string | 是 | 文件路径 | | callback | AsyncCallback<string> | 是 | 异步获取数据标签之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 13900001 | Operation not permitted | +| 13900007 | Arg list too long | +| 13900015 | File exists | +| 13900020 | Invalid argument | +| 13900025 | No space left on device | +| 13900037 | No data available | +| 13900041 | Quota exceeded | +| 13900042 | Unknown error | + **示例:** ```js @@ -183,6 +258,7 @@ getSecurityLabel(path:string, callback:AsyncCallback<string>): void } }); ``` + ## securityLabel.getSecurityLabelSync getSecurityLabelSync(path:string):string @@ -203,6 +279,21 @@ getSecurityLabelSync(path:string):string | ------ | ------------ | | string | 返回数据标签 | +**错误码:** + +以下错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 13900001 | Operation not permitted | +| 13900007 | Arg list too long | +| 13900015 | File exists | +| 13900020 | Invalid argument | +| 13900025 | No space left on device | +| 13900037 | No data available | +| 13900041 | Quota exceeded | +| 13900042 | Unknown error | + **示例:** ```js diff --git a/zh-cn/application-dev/reference/apis/js-apis-file-statvfs.md b/zh-cn/application-dev/reference/apis/js-apis-file-statvfs.md index f479d0de61..894515ff1d 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-file-statvfs.md +++ b/zh-cn/application-dev/reference/apis/js-apis-file-statvfs.md @@ -3,14 +3,15 @@ 该模块提供文件系统相关存储信息的功能,向应用程序提供获取文件系统总字节数、空闲字节数的JS接口。 > **说明:** +> > 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 -> 本模块支持对错误码进行处理,错误码及其适配方式[参考文档](../errorcodes/errorcode-filemanagement.md#错误码适配指导)。 ## 导入模块 ```js import statvfs from '@ohos.file.statvfs'; ``` + ## statvfs.getFreeSize getFreeSize(path:string):Promise<number> @@ -31,6 +32,10 @@ getFreeSize(path:string):Promise<number> | --------------------- | -------------- | | Promise<number> | 返回空闲字节数 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -57,6 +62,10 @@ getFreeSize(path:string, callback:AsyncCallback<number>): void | path | string | 是 | 需要查询的文件系统的文件路径 | | callback | AsyncCallback<number> | 是 | 异步获取空闲字节数之后的回调 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -90,6 +99,10 @@ getTotalSize(path: string): Promise<number> | --------------------- | ------------ | | Promise<number> | 返回总字节数 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -116,6 +129,10 @@ getTotalSize(path: string, callback: AsyncCallback<number>): void | path | string | 是 | 需要查询的文件系统的文件路径 | | callback | AsyncCallback<number> | 是 | 异步获取总字节数之后的回调 | +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + **示例:** ```js @@ -128,4 +145,3 @@ getTotalSize(path: string, callback: AsyncCallback<number>): void } }); ``` - diff --git a/zh-cn/application-dev/reference/apis/js-apis-file-storage-statistics.md b/zh-cn/application-dev/reference/apis/js-apis-file-storage-statistics.md index f918ebd6e7..cc250675db 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-file-storage-statistics.md +++ b/zh-cn/application-dev/reference/apis/js-apis-file-storage-statistics.md @@ -4,8 +4,8 @@ > **说明:** > -> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 -> - 本模块支持对错误码进行处理,错误码及其适配方式[参考文档](../errorcodes/errorcode-filemanagement.md#错误码适配指导)。 +> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + ## 导入模块 ```js @@ -24,7 +24,6 @@ getTotalSizeOfVolume(volumeUuid: string): Promise<number> **系统接口:** 该接口为系统接口。 - **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -37,6 +36,19 @@ getTotalSizeOfVolume(volumeUuid: string): Promise<number> | --------------------- | ---------------- | | Promise<number> | 返回指定卷设备的总空间大小(单位为Byte) | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -60,7 +72,6 @@ getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): **系统接口:** 该接口为系统接口。 - **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -68,6 +79,19 @@ getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): | volumeUuid | string | 是 | 卷设备uuid | | callback | AsyncCallback<number> | 是 | 获取指定卷设备总空间之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -90,7 +114,6 @@ getFreeSizeOfVolume(volumeUuid: string): Promise<number> **系统接口:** 该接口为系统接口。 - **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -103,6 +126,19 @@ getFreeSizeOfVolume(volumeUuid: string): Promise<number> | --------------------- | ------------------ | | Promise<number> | 返回指定卷的可用空间大小(单位为Byte) | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -127,7 +163,6 @@ getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): **系统接口:** 该接口为系统接口。 - **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -135,6 +170,19 @@ getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): | volumeUuid | string | 是 | 卷设备uuid | | callback | AsyncCallback<number> | 是 | 获取指定卷可用空间之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -157,7 +205,6 @@ getBundleStats(packageName: string): Promise<BundleStats> **系统接口:** 该接口为系统接口。 - **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -170,6 +217,19 @@ getBundleStats(packageName: string): Promise<BundleStats> | ------------------------------------------ | -------------------------- | | Promise<[Bundlestats](#bundlestats9)> | 返回指定卷上的应用存储数据(单位为Byte) | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -193,7 +253,6 @@ getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>) **系统接口:** 该接口为系统接口。 - **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -201,6 +260,19 @@ getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>) | packageName | string | 是 | 应用包名 | | callback | AsyncCallback<[Bundlestats](#bundlestats9)> | 是 | 获取指定卷上的应用存储数据之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -225,6 +297,16 @@ getCurrentBundleStats(): Promise<BundleStats> | ------------------------------------------ | -------------------------- | | Promise<[Bundlestats](#bundlestats9)> | 返回指定卷上的应用存空间大小(单位为Byte) | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -246,6 +328,16 @@ getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void | -------- | --------------------------------------------------------- | ---- | ------------------------------------ | | callback | AsyncCallback<[BundleStats](#bundlestats9)> | 是 | 获取指定卷上的应用存储空间大小之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -257,7 +349,7 @@ getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void ## BundleStats9+ -**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics +**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics | 名称 | 类型 | 可读 | 可写 | 说明 | | --------- | ------ | --- | ---- | -------------- | @@ -265,7 +357,6 @@ getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void | cacheSize | number | 是 | 否 | 缓存数据大小(单位为Byte) | | dataSize | number | 是 | 否 | 应用总数据大小(单位为Byte) | - ## storageStatistics.getTotalSize9+ getTotalSize(): Promise<number> @@ -284,6 +375,18 @@ getTotalSize(): Promise<number> | --------------------- | ------------------ | | Promise<number> | 返回内置存储的总空间大小(单位为Byte) | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -309,6 +412,18 @@ getTotalSize(callback: AsyncCallback<number>): void | -------- | ------------------------------------ | ---- | ------------------------ | | callback | AsyncCallback<number> | 是 | 获取内置存储的总空间大小之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -318,7 +433,6 @@ getTotalSize(callback: AsyncCallback<number>): void }); ``` - ## storageStatistics.getFreeSize9+ getFreeSize(): Promise<number> @@ -337,6 +451,18 @@ getFreeSize(): Promise<number> | --------------------- | ------------------ | | Promise<number> | 返回内置存储的可用空间大小(单位为Byte) | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -344,7 +470,6 @@ getFreeSize(): Promise<number> console.info("getFreeSize successfully:"+ JSON.stringify(number)); ``` - ## storageStatistics.getFreeSize9+ getFreeSize(callback: AsyncCallback<number>): void @@ -363,6 +488,18 @@ getFreeSize(callback: AsyncCallback<number>): void | -------- | ------------------------------------ | ---- | ------------------------- | | callback | AsyncCallback<number> | 是 | 获取内置存储的可用空间大小之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -384,13 +521,24 @@ getSystemSize(): Promise<number> **系统接口:** 该接口为系统接口。 - **返回值:** | 类型 | 说明 | | --------------------- | ---------------- | | Promise<number> | 返回系统数据的空间大小(单位为Byte) | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -419,6 +567,18 @@ getSystemSize(callback: AsyncCallback<number>): void | ---------- | ------------------------------------ | ---- | -------------------------- | | callback | AsyncCallback<number> | 是 | 获取系统数据的空间大小之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -446,6 +606,18 @@ getUserStorageStats(): Promise<StorageStats> | --------------------- | ---------------- | | Promise<[StorageStats](#storagestats9)> | 返回当前用户各类别存储空间大小(单位为Byte) | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -474,6 +646,18 @@ getUserStorageStats(callback: AsyncCallback<StorageStats>): void | ---------- | ------------------------------------ | ---- | -------------------------- | | callback | AsyncCallback<[StorageStats](#storagestats9)> | 是 | 返回用户各类别存储空间大小之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -482,6 +666,7 @@ getUserStorageStats(callback: AsyncCallback<StorageStats>): void console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats)); }); ``` + getUserStorageStats(userId: number): Promise<StorageStats> 异步获取指定用户各类别存储空间大小(单位为Byte),以promise方式返回。 @@ -504,6 +689,19 @@ getUserStorageStats(userId: number): Promise<StorageStats> | --------------------- | ---------------- | | Promise<[StorageStats](#storagestats9)> | 返回指定用户各类别存储空间大小(单位为Byte) | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600009 | User if out of range. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -534,6 +732,19 @@ getUserStorageStats(userId: number, callback: AsyncCallback<StorageStats>) | userId | number | 是 | 用户id | | callback | AsyncCallback<[StorageStats](#storagestats9)> | 是 | 返回各类别数据大小之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600009 | User if out of range. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -544,10 +755,9 @@ getUserStorageStats(userId: number, callback: AsyncCallback<StorageStats>) }); ``` - ## StorageStats9+ -**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics +**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统接口:** 该接口为系统接口。 diff --git a/zh-cn/application-dev/reference/apis/js-apis-file-volumemanager.md b/zh-cn/application-dev/reference/apis/js-apis-file-volumemanager.md index 289147e5a4..e68fb84dd6 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-file-volumemanager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-file-volumemanager.md @@ -6,7 +6,6 @@ > > - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > - 本模块接口为系统接口。 -> - 本模块支持对错误码进行处理,错误码及其适配方式[参考文档](../errorcodes/errorcode-filemanagement.md#错误码适配指导)。 ## 导入模块 @@ -30,6 +29,18 @@ getAllVolumes(): Promise<Array<Volume>> | ---------------------------------- | -------------------------- | | Promise<[Volume](#volume)[]> | 返回当前所有可获得的卷设备信息 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -56,6 +67,18 @@ getAllVolumes(callback: AsyncCallback<Array<Volume>>): void | -------- | ------------------------------------------------- | ---- | ------------------------------------ | | callback | AsyncCallback<[Volume](#volume)[]> | 是 | 获取当前所有可获得的卷设备信息之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -65,7 +88,6 @@ getAllVolumes(callback: AsyncCallback<Array<Volume>>): void }); ``` - ## volumemanager.mount mount(volumeId: string): Promise<void> @@ -88,6 +110,22 @@ mount(volumeId: string): Promise<void> | ---------------------- | ---------- | | Promise<void> | 挂载指定卷设备 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600002 | Not supported filesystem. | +| 13600003 | Failed to mount. | +| 13600005 | Incorrect volume state. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -116,6 +154,22 @@ mount(volumeId: string, callback:AsyncCallback<void>):void | volumeId | string | 是 | 卷设备id | | callback | AsyncCallback<void> | 是 | 挂载指定卷设备之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600002 | Not supported filesystem. | +| 13600003 | Failed to mount. | +| 13600005 | Incorrect volume state. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -147,6 +201,22 @@ unmount(volumeId: string): Promise<void> | ---------------------- | ---------- | | Promise<void> | 卸载指定卷设备 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600002 | Not supported filesystem. | +| 13600004 | Failed to unmount. | +| 13600005 | Incorrect volume state. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -175,6 +245,22 @@ unmount(volumeId: string, callback: AsyncCallback<void>): void | volumeId | string | 是 | 卷设备id | | callback | AsyncCallback<void> | 是 | 卸载指定卷设备之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600002 | Not supported filesystem. | +| 13600004 | Failed to unmount. | +| 13600005 | Incorrect volume state. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -206,6 +292,19 @@ getVolumeByUuid(uuid: string): Promise<Volume> | ---------------------------------- | -------------------------- | | Promise<[Volume](#volume)> | 返回当前所有可获得的卷设备信息 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -234,6 +333,19 @@ getVolumeByUuid(uuid: string, callback: AsyncCallback<Volume>): void | uuid | string | 是 | 卷设备uuid | | callback | AsyncCallback<[Volume](#volume)> | 是 | 获取卷设备信息之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -265,6 +377,19 @@ getVolumeById(volumeId: string): Promise<Volume> | ---------------------------------- | -------------------------- | | Promise<[Volume](#volume)> | 返回当前所有可获得的卷设备信息 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -293,6 +418,19 @@ getVolumeById(volumeId: string, callback: AsyncCallback<Volume>): void | volumeId | string | 是 | 卷设备id | | callback | AsyncCallback<[Volume](#volume)> | 是 | 获取卷设备信息之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -325,6 +463,21 @@ setVolumeDescription(uuid: string, description: string): Promise<void> | ---------------------- | -------------------------- | | Promise<void> | 设置卷设备信息 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600002 | Not supported filesystem. | +| 13600005 | Incorrect volume state. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -355,6 +508,21 @@ setVolumeDescription(uuid: string, description: string, callback: AsyncCallback& | description | string | 是 | 卷设备描述 | | callback | AsyncCallback<void> | 是 | 设置卷描述之后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600002 | Not supported filesystem. | +| 13600005 | Incorrect volume state. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -388,6 +556,21 @@ format(volumeId: string, fsType: string): Promise<void> | ---------------------- | ---------- | | Promise<void> | 对指定卷设备进行格式化 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600002 | Not supported filesystem. | +| 13600005 | Incorrect volume state. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -418,6 +601,21 @@ format(volumeId: string, fsType: string, callback: AsyncCallback<void>): v | fsType | string | 是 | 文件系统类型(vfat或者exfat) | | callback | AsyncCallback<void> | 是 | 对指定卷设备格式化后的回调 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600002 | Not supported filesystem. | +| 13600005 | Incorrect volume state. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -451,6 +649,19 @@ partition(diskId: string, type: number): Promise<void> | --------------------- | ----------------------- | | Promise<void> | 对磁盘进行分区 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js @@ -481,6 +692,19 @@ partition(diskId: string, type: number, callback: AsyncCallback<void>): vo | type | number | 是 | 分区类型 | | callback | AsyncCallback<void> | 是 | 对磁盘设备进行分区 | +**错误码:** + +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | +| 13600008 | No such object. | +| 13900032 | Unknown error. | + **示例:** ```js diff --git a/zh-cn/application-dev/reference/apis/js-apis-fileAccess.md b/zh-cn/application-dev/reference/apis/js-apis-fileAccess.md index e776b1aa45..75758d56f8 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-fileAccess.md +++ b/zh-cn/application-dev/reference/apis/js-apis-fileAccess.md @@ -4,9 +4,8 @@ fileAccess模块是基于extension机制实现的一个对公共文件访问和 >**说明:** > ->- 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 ->- 本模块接口为系统接口,三方应用不支持调用,当前只支持filepicker、文件管理器调用。 ->- 本模块支持对错误码进行处理,错误码及其适配方式[参考文档](../errorcodes/errorcode-filemanagement.md#错误码适配指导)。 +> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +> - 本模块接口为系统接口,三方应用不支持调用,当前只支持FilePicker、文件管理器调用。 ## 导入模块 @@ -16,10 +15,12 @@ import fileAccess from '@ohos.file.fileAccess'; ## fileAccess.getFileAccessAbilityInfo -getFileAccessAbilityInfo( ) : Promise<Array<Want>> +getFileAccessAbilityInfo() : Promise<Array<Want>> 以异步方法获取系统内extension配置为fileAccess类型的所有Want信息。使用Promise异步回调。 +**模型约束**:此接口仅可在Stage模型下使用。 + **系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER 和 ohos.permission.GET_BUNDLE_INFO_PRIVILEGED @@ -28,7 +29,11 @@ getFileAccessAbilityInfo( ) : Promise<Array<Want>> | 类型 | 说明 | | --- | -- | - | Promise<Array<Want>> | 表示当前系统配置fileAccess的所有文件管理类服务 | + | Promise<Array<[Want](js-apis-app-ability-want.md)>> | 表示当前系统配置fileAccess的所有文件管理类服务 | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** @@ -46,10 +51,12 @@ getFileAccessAbilityInfo( ) : Promise<Array<Want>> ## fileAccess.getFileAccessAbilityInfo -getFileAccessAbilityInfo(callback: AsyncCallback<Array<Want>>): void; +getFileAccessAbilityInfo(callback: AsyncCallback<Array<Want>>): void 以异步方法获取系统内extension配置为fileAccess类型的所有Want信息。使用callback异步回调。 +**模型约束**:此接口仅可在Stage模型下使用。 + **系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER 和 ohos.permission.GET_BUNDLE_INFO_PRIVILEGED @@ -58,7 +65,11 @@ getFileAccessAbilityInfo(callback: AsyncCallback<Array<Want>>): void | 参数名 | 类型 | 必填 | 说明 | | --- | --- | --- | -- | - | callback | AsyncCallback<Array<Want>> | 是 | 表示当前系统配置fileAccess的所有文件管理类服务 | + | callback | AsyncCallback<Array<[Want](js-apis-app-ability-want.md)>> | 是 | 表示当前系统配置fileAccess的所有文件管理类服务 | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** @@ -84,6 +95,8 @@ createFileAccessHelper(context: Context, wants: Array<Want>) : FileAccessH 以同步方法创建连接指定wants的helper对象。 +**模型约束**:此接口仅可在Stage模型下使用。 + **系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER 和 ohos.permission.GET_BUNDLE_INFO_PRIVILEGED @@ -92,14 +105,18 @@ createFileAccessHelper(context: Context, wants: Array<Want>) : FileAccessH | 参数名 | 类型 | 必填 | 说明 | | --- | --- | --- | -- | - | context | Context | 是 | 代表ability的上下文的能力 | - | wants | Array<Want> | 是 | Want是一种基本通信组件,主要用于服务拉起 | + | context | [Context](js-apis-inner-application-context.md) | 是 | 代表ability的上下文的能力 | + | wants | Array<[Want](js-apis-app-ability-want.md)> | 是 | Want是一种基本通信组件,主要用于服务拉起 | **返回值:** | 类型 | 说明 | | --- | -- | - | FileAccessHelper | 提供文件访问和操作能力的helper对象 | + | [FileAccessHelper](#fileaccesshelper) | 提供文件访问和操作能力的helper对象 | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** @@ -131,6 +148,8 @@ createFileAccessHelper(context: Context) : FileAccessHelper 以同步方法创建连接当前系统内所有文件管理服务的helper对象。 +**模型约束**:此接口仅可在Stage模型下使用。 + **系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER 和 ohos.permission.GET_BUNDLE_INFO_PRIVILEGED @@ -139,13 +158,17 @@ createFileAccessHelper(context: Context) : FileAccessHelper | 参数名 | 类型 | 必填 | 说明 | | --- | --- | --- | -- | - | context | Context | 是 | ability的上下文的能力 | + | context | [Context](js-apis-inner-application-context.md) | 是 | ability的上下文的能力 | **返回值:** | 类型 | 说明 | | --- | -- | - | FileAccessHelper | 提供文件访问和操作的能力的helper对象 | + | [FileAccessHelper](#fileaccesshelper) | 提供文件访问和操作的能力的helper对象 | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** @@ -164,99 +187,34 @@ createFileAccessHelper(context: Context) : FileAccessHelper } ``` -## FileAccessHelper.getRoots - -getRoots( ) : Promise<RootIterator> - -以异步方法获取helper对象连接的文件管理服务类的设备根节点信息。使用Promise异步回调。 -该方法返回迭代器对象RootIterator,然后通过[next](#rootiteratornext)方法返回[RootInfo](#rootinfo)。 - -**系统能力**:SystemCapability.FileManagement.UserFileService - -**需要权限**:ohos.permission.FILE_ACCESS_MANAGER - -**返回值:** - - | 类型 | 说明 | - | --- | -- | - | Promise<RootIterator> | 根设备目录信息组成迭代器对象 | - -**示例:** - - ```js - async getRoots() { - let rootIterator = null; - let rootinfos = []; - let isDone = false; - try { - // fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取 - rootIterator = await fileAccessHelper.getRoots(); - if (!rootIterator) { - console.error("getRoots interface returns an undefined object"); - return; - } - while (!isDone) { - let result = rootIterator.next(); - console.log("next result = " + JSON.stringify(result)); - isDone = result.done; - if (!isDone) - rootinfos.push(result.value); - } - } catch (error) { - console.error("getRoots failed, errCode:" + error.code + ", errMessage:" + error.message); - } - } - ``` - -## FileAccessHelper.getRoots +## FileInfo -getRoots(callback:AsyncCallback<RootIterator>) : void; +表示文件(夹)属性信息和接口能力。 -以异步方法获取helper对象连接的文件管理服务类的设备根节点信息。使用callback异步回调。 -callback带回迭代器对象RootIterator,然后通过[next](#rootiteratornext)方法返回[RootInfo](#rootinfo)。 +**模型约束**:此接口仅可在Stage模型下使用。 -**系统能力**:SystemCapability.FileManagement.UserFileService +**系统能力**:SystemCapability.FileManagement.UserFileService。 **需要权限**:ohos.permission.FILE_ACCESS_MANAGER -**参数:** - - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | callback | AsyncCallback<RootIterator> | 是 | 根设备目录信息组成迭代器对象 | - -**示例:** +### 属性 - ```js - async getRoots() { - let rootinfos = []; - let isDone = false; - try { - // fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取 - fileAccessHelper.getRoots(function (err, rootIterator) { - if (err) { - console.error("Failed to getRoots in async, errCode:" + err.code + ", errMessage:" + err.message); - return; - } - while (!isDone) { - let result = rootIterator.next(); - console.log("next result = " + JSON.stringify(result)); - isDone = result.done; - if (!isDone) - rootinfos.push(result.value); - } - }); - } catch (error) { - console.error("getRoots failed, errCode:" + error.code + ", errMessage:" + error.message); - } - } - ``` +| 名称 | 类型 | 可读 | 可写 | 说明 | +| ------ | ------ | -------- | ------ | -------- | +| uri | string | 是 | 否 | 文件(夹)的uri | +| fileName | string | 是 | 否 | 文件(夹)的名称 | +| mode | number | 是 | 否 | 文件(夹)的权限信息 | +| size | number | 是 | 否 | 文件(夹)的大小 | +| mtime | number | 是 | 否 | 文件(夹)的修改时间 | +| mimeType | string | 是 | 否 | 文件(夹)的媒体资源类型 | -## RootInfo.listfile +### listFile listFile(filter?: Filter) : FileIterator -以同步方法从某设备根节点开始,基于过滤器,获取第一级符合条件的文件(夹)信息的迭代器对象FileIterator,然后通过[next](#fileiteratornext)方法返回[FileInfo](#fileinfo)。目前仅支持内置存储设备过滤,外置存储设备不支持过滤。 +以同步方法从某个目录,基于过滤器,获取下一级符合条件的文件(夹)信息的迭代器对象FileIterator,然后通过[next](#next)方法返回[FileInfo](#fileinfo)。目前仅支持内置存储设备过滤,外置存储设备不支持过滤。 + +**模型约束**:此接口仅可在Stage模型下使用。 **系统能力**:SystemCapability.FileManagement.UserFileService @@ -266,25 +224,28 @@ listFile(filter?: Filter) : FileIterator | 参数名 | 类型 | 必填 | 说明 | | --- | --- | -- | -- | - | filter | Filter | 否 | 过滤器对象 | - + | filter | [Filter](js-apis-file-fs.md#filter) | 否 | 过滤器对象 | **返回值:** | 类型 | 说明 | | --- | -- | - | FileIterator | 文件(夹)信息的迭代器对象FileIterator | + | [FileIterator](#fileiterator) | 文件(夹)信息的迭代器对象FileIterator | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** ```js - // rootinfos 从getRoots()获取 - // let filter = {suffix : [".txt", ".jpg", ".xlsx"]}; - let rootInfo = rootinfos[0]; - let fileInfos = []; + // fileInfoDir 表示某个目录信息 + // let filter = { suffix : [".txt", ".jpg", ".xlsx"] }; + let fileInfoDir = fileInfos[0]; + let subfileInfos = []; let isDone = false; try { - let fileIterator = rootInfo.listFile(); + let fileIterator = fileInfoDir.listFile(); // 含过滤器实现的listFile // let fileIterator = rootInfo.listFile(filter); if (!fileIterator) { @@ -296,18 +257,20 @@ listFile(filter?: Filter) : FileIterator console.log("next result = " + JSON.stringify(result)); isDone = result.done; if (!isDone) - fileInfos.push(result.value); + subfileInfos.push(result.value); } } catch (error) { console.error("listFile failed, errCode:" + error.code + ", errMessage:" + error.message); } ``` -## RootInfo.scanFile +### scanFile scanFile(filter?: Filter) : FileIterator -以同步方法从某设备根节点开始,基于过滤器,递归获取符合条件的文件信息的迭代器对象FileIterator,然后通过[next](#fileiteratornext)方法返回[FileInfo](#fileinfo)。目前仅支持内置存储设备。 +以同步方法从某个目录,基于过滤器,递归获取符合条件的文件信息的迭代器对象FileIterator,然后通过[next](#next)方法返回[FileInfo](#fileinfo)。目前仅支持内置存储设备。 + +**模型约束**:此接口仅可在Stage模型下使用。 **系统能力**:SystemCapability.FileManagement.UserFileService @@ -317,28 +280,32 @@ scanFile(filter?: Filter) : FileIterator | 参数名 | 类型 | 必填 | 说明 | | --- | --- | -- | -- | - | filter | Filter | 否 | 过滤器对象 | + | filter | [Filter](js-apis-file-fs.md#filter) | 否 | 过滤器对象 | **返回值:** | 类型 | 说明 | | --- | -- | - | FileIterator | 文件信息的迭代器对象FileIterator | + | [FileIterator](#fileiterator) | 文件信息的迭代器对象FileIterator | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** ```js - // rootInfos 从 getRoots()获取 + // fileInfoDir 表示某个目录信息 // let filter = {suffix : [".txt", ".jpg", ".xlsx"]}; - let rootInfo = rootInfos[0]; - let fileInfos = []; + let fileInfoDir = fileInfos[0]; + let subfileInfos = []; let isDone = false; try { - let fileIterator = rootInfo.scanFile(); + let fileIterator = fileInfoDir.scanFile(); // 含过滤器实现的scanFile // let fileIterator = rootInfo.scanFile(filter); if (!fileIterator) { - console.error("scanFile interface returns undefined object"); + console.error("scanFile interface returns an undefined object"); return; } while (!isDone) { @@ -346,18 +313,71 @@ scanFile(filter?: Filter) : FileIterator console.log("next result = " + JSON.stringify(result)); isDone = result.done; if (!isDone) - fileInfos.push(result.value); + subfileInfos.push(result.value); } } catch (error) { console.error("scanFile failed, errCode:" + error.code + ", errMessage:" + error.message); } ``` -## FileInfo.listfile +## FileIterator + +表示文件夹的迭代器对象。 + +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService + +**需要权限**:ohos.permission.FILE_ACCESS_MANAGER + +### next + +next() : { value: FileInfo, done: boolean } + +可以通过next同步方法获取下一级文件(夹)信息。 + +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService。 + +**需要权限**:ohos.permission.FILE_ACCESS_MANAGER + +**返回值:** + +| 类型 | 说明 | +| --- | -- | +| {value: [FileInfo](#fileinfo), done: boolean} | 通过next遍历文件夹,直到done返回true结束;value字段返回fileInfo。| + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +## RootInfo + +表示设备的根属性信息和接口能力。 + +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService。 + +**需要权限**:ohos.permission.FILE_ACCESS_MANAGER + +### 属性 + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| ------ | ------ | -------- | ------ | -------- | +| deviceType | number | 是 | 否 |设备类型 | +| uri | string | 是 | 否 | 设备根目录Uri | +| displayName | string | 是 | 否 | 设备名称 | +| deviceFlags | number | 是 | 否 | 设备支持的能力 | + +### listFile listFile(filter?: Filter) : FileIterator -以同步方法从某个目录,基于过滤器,获取下一级符合条件的文件(夹)信息的迭代器对象FileIterator,然后通过[next](#fileiteratornext)方法返回[FileInfo](#fileinfo)。目前仅支持内置存储设备过滤,外置存储设备不支持过滤。 +以同步方法从某设备根节点开始,基于过滤器,获取第一级符合条件的文件(夹)信息的迭代器对象FileIterator,然后通过[next](#next)方法返回[FileInfo](#fileinfo)。目前仅支持内置存储设备过滤,外置存储设备不支持过滤。 + +**模型约束**:此接口仅可在Stage模型下使用。 **系统能力**:SystemCapability.FileManagement.UserFileService @@ -367,24 +387,28 @@ listFile(filter?: Filter) : FileIterator | 参数名 | 类型 | 必填 | 说明 | | --- | --- | -- | -- | - | filter | Filter | 否 | 过滤器对象 | + | filter | [Filter](js-apis-file-fs.md#filter) | 否 | 过滤器对象 | **返回值:** | 类型 | 说明 | | --- | -- | - | FileIterator | 文件(夹)信息的迭代器对象FileIterator | + | [FileIterator](#fileiterator) | 文件(夹)信息的迭代器对象FileIterator | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** ```js - // fileInfoDir 表示某个目录信息 - // let filter = { suffix : [".txt", ".jpg", ".xlsx"] }; - let fileInfoDir = fileInfos[0]; - let subfileInfos = []; + // rootinfos 从getRoots()获取 + // let filter = {suffix : [".txt", ".jpg", ".xlsx"]}; + let rootInfo = rootinfos[0]; + let fileInfos = []; let isDone = false; try { - let fileIterator = fileInfoDir.listFile(); + let fileIterator = rootInfo.listFile(); // 含过滤器实现的listFile // let fileIterator = rootInfo.listFile(filter); if (!fileIterator) { @@ -396,18 +420,20 @@ listFile(filter?: Filter) : FileIterator console.log("next result = " + JSON.stringify(result)); isDone = result.done; if (!isDone) - subfileInfos.push(result.value); + fileInfos.push(result.value); } } catch (error) { console.error("listFile failed, errCode:" + error.code + ", errMessage:" + error.message); } ``` -## FileInfo.scanfile +### scanFile -scanFile(filter?: Filter) : FileIterator; +scanFile(filter?: Filter) : FileIterator + +以同步方法从某设备根节点开始,基于过滤器,递归获取符合条件的文件信息的迭代器对象FileIterator,然后通过[next](#next)方法返回[FileInfo](#fileinfo)。目前仅支持内置存储设备。 -以同步方法从某个目录,基于过滤器,递归获取符合条件的文件信息的迭代器对象FileIterator,然后通过[next](#fileiteratornext)方法返回[FileInfo](#fileinfo)。目前仅支持内置存储设备。 +**模型约束**:此接口仅可在Stage模型下使用。 **系统能力**:SystemCapability.FileManagement.UserFileService @@ -417,29 +443,32 @@ scanFile(filter?: Filter) : FileIterator; | 参数名 | 类型 | 必填 | 说明 | | --- | --- | -- | -- | - | filter | Filter | 否 | 过滤器对象 | - + | filter | [Filter](js-apis-file-fs.md#filter) | 否 | 过滤器对象 | **返回值:** | 类型 | 说明 | | --- | -- | - | FileIterator | 文件信息的迭代器对象FileIterator | + | [FileIterator](#fileiterator) | 文件信息的迭代器对象FileIterator | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** ```js - // fileInfoDir 表示某个目录信息 + // rootInfos 从 getRoots()获取 // let filter = {suffix : [".txt", ".jpg", ".xlsx"]}; - let fileInfoDir = fileInfos[0]; - let subfileInfos = []; + let rootInfo = rootInfos[0]; + let fileInfos = []; let isDone = false; try { - let fileIterator = fileInfoDir.scanFile(); + let fileIterator = rootInfo.scanFile(); // 含过滤器实现的scanFile // let fileIterator = rootInfo.scanFile(filter); if (!fileIterator) { - console.error("scanFile interface returns an undefined object"); + console.error("scanFile interface returns undefined object"); return; } while (!isDone) { @@ -447,29 +476,173 @@ scanFile(filter?: Filter) : FileIterator; console.log("next result = " + JSON.stringify(result)); isDone = result.done; if (!isDone) - subfileInfos.push(result.value); + fileInfos.push(result.value); } } catch (error) { console.error("scanFile failed, errCode:" + error.code + ", errMessage:" + error.message); } ``` -## FileAccessHelper.createFile +## RootIterator + +表示设备根目录的迭代器对象。 + +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService + +**需要权限**:ohos.permission.FILE_ACCESS_MANAGER + +### next + +next() : { value: RootInfo, done: boolean } + +通过next同步方法获取下一级设备根目录。 + +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService。 + +**需要权限**:ohos.permission.FILE_ACCESS_MANAGER + +**返回值:** + +| 类型 | 说明 | +| --- | -- | +| {value: [RootInfo](#rootinfo), done: boolean} | 通过next遍历文件夹,直到done返回true结束;value字段返回rootInfo。| + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +## FileAccessHelper + +FileAccessHelper对象。 + +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService + +**需要权限**:ohos.permission.FILE_ACCESS_MANAGER + +### getRoots + +getRoots() : Promise<RootIterator> + +以异步方法获取helper对象连接的文件管理服务类的设备根节点信息。使用Promise异步回调。 +该方法返回迭代器对象RootIterator,然后通过[next](#next-1)方法返回[RootInfo](#rootinfo)。 + +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService + +**需要权限**:ohos.permission.FILE_ACCESS_MANAGER + +**返回值:** + +| 类型 | 说明 | +| --- | -- | +| Promise<[RootIterator](#rootiterator)> | 根设备目录信息组成迭代器对象 | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +**示例:** + + ```js + async getRoots() { + let rootIterator = null; + let rootinfos = []; + let isDone = false; + try { + // fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取 + rootIterator = await fileAccessHelper.getRoots(); + if (!rootIterator) { + console.error("getRoots interface returns an undefined object"); + return; + } + while (!isDone) { + let result = rootIterator.next(); + console.log("next result = " + JSON.stringify(result)); + isDone = result.done; + if (!isDone) + rootinfos.push(result.value); + } + } catch (error) { + console.error("getRoots failed, errCode:" + error.code + ", errMessage:" + error.message); + } + } + ``` + +### getRoots + +getRoots(callback:AsyncCallback<RootIterator>) : void + +以异步方法获取helper对象连接的文件管理服务类的设备根节点信息。使用callback异步回调。 +callback带回迭代器对象RootIterator,然后通过[next](#next-1)方法返回[RootInfo](#rootinfo)。 + +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService + +**需要权限**:ohos.permission.FILE_ACCESS_MANAGER + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| callback | AsyncCallback<[RootIterator](#rootiterator)> | 是 | 根设备目录信息组成迭代器对象 | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + +**示例:** + + ```js + async getRoots() { + let rootinfos = []; + let isDone = false; + try { + // fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取 + fileAccessHelper.getRoots(function (err, rootIterator) { + if (err) { + console.error("Failed to getRoots in async, errCode:" + err.code + ", errMessage:" + err.message); + return; + } + while (!isDone) { + let result = rootIterator.next(); + console.log("next result = " + JSON.stringify(result)); + isDone = result.done; + if (!isDone) + rootinfos.push(result.value); + } + }); + } catch (error) { + console.error("getRoots failed, errCode:" + error.code + ", errMessage:" + error.message); + } + } + ``` + +### createFile createFile(uri: string, displayName: string) : Promise<string> 以异步方法创建文件到指定目录,返回新文件uri。使用Promise异步回调。 +**模型约束**:此接口仅可在Stage模型下使用。 + **系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | uri | string | 是 | 表示需要创建文件的父目录的Uri | - | displayName | string | 是 | 待创建文件的名称,默认本地文件需要添加后缀 | +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| uri | string | 是 | 表示需要创建文件的父目录的Uri | +| displayName | string | 是 | 待创建文件的名称,默认本地文件需要添加后缀 | **返回值:** @@ -477,6 +650,10 @@ createFile(uri: string, displayName: string) : Promise<string> | --- | -- | | Promise<string> | 新创建的文件的uri | +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + **示例:** ```js @@ -499,23 +676,29 @@ createFile(uri: string, displayName: string) : Promise<string> }; ``` -## FileAccessHelper.createFile +### createFile -createFile(uri: string, displayName: string, callback: AsyncCallback<string>) : void; +createFile(uri: string, displayName: string, callback: AsyncCallback<string>) : void 以异步方法创建文件到指定目录,返回新文件uri。使用callback异步回调。 +**模型约束**:此接口仅可在Stage模型下使用。 + **系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | uri | string | 是 | 表示需要创建文件的父目录的Uri | - | displayName | string | 是 | 待创建文件的名称,默认本地文件需要添加后缀 | - | callback | AsyncCallback<string> | 是 | 新创建的文件的uri | +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| uri | string | 是 | 表示需要创建文件的父目录的Uri | +| displayName | string | 是 | 待创建文件的名称,默认本地文件需要添加后缀 | +| callback | AsyncCallback<string> | 是 | 新创建的文件的uri | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** @@ -539,22 +722,24 @@ createFile(uri: string, displayName: string, callback: AsyncCallback<string&g }; ``` -## FileAccessHelper.mkDir +### mkDir mkDir(parentUri: string, displayName: string) : Promise<string> 以异步方法创建文件夹到指定目录,返回文件夹uri。使用Promise异步回调。 +**模型约束**:此接口仅可在Stage模型下使用。 + **系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | parentUri | string | 是 | 表示需要创建文件夹的父目录的Uri | - | displayName | string | 是 | 待创建文件夹的名称| +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| parentUri | string | 是 | 表示需要创建文件夹的父目录的Uri | +| displayName | string | 是 | 待创建文件夹的名称| **返回值:** @@ -562,6 +747,10 @@ mkDir(parentUri: string, displayName: string) : Promise<string> | --- | -- | | Promise<string> | 新创建的文件夹的uri | +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + **示例:** ```js @@ -584,23 +773,29 @@ mkDir(parentUri: string, displayName: string) : Promise<string> }; ``` -## FileAccessHelper.mkDir +### mkDir -mkDir(parentUri: string, displayName: string, callback: AsyncCallback<string>) : void; +mkDir(parentUri: string, displayName: string, callback: AsyncCallback<string>) : void 以异步方法创建文件夹到指定目录,返回文件夹uri。使用callback异步回调。 +**模型约束**:此接口仅可在Stage模型下使用。 + **系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | parentUri | string | 是 | 表示需要创建文件夹的父目录的Uri | - | displayName | string | 是 | 待创建文件夹的名称| - | callback | AsyncCallback<string> | 是 | 新创建的文件夹的uri | +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| parentUri | string | 是 | 表示需要创建文件夹的父目录的Uri | +| displayName | string | 是 | 待创建文件夹的名称| +| callback | AsyncCallback<string> | 是 | 新创建的文件夹的uri | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** @@ -624,22 +819,24 @@ mkDir(parentUri: string, displayName: string, callback: AsyncCallback<string& }; ``` -## FileAccessHelper.openFile +### openFile openFile(uri: string, flags: OPENFLAGS) : Promise<number> 以异步方法打开文件,返回文件描述符。使用Promise异步回调。 -**系统能力**:SystemCapability.FileManagement.UserFileService。 +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | uri | string | 是 | 待打开文件的uri | - | flags | [OPENFLAGS](#openflags) | 是 | 文件打开的标志 | +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| uri | string | 是 | 待打开文件的uri | +| flags | [OPENFLAGS](#openflags) | 是 | 文件打开的标志 | **返回值:** @@ -647,6 +844,10 @@ openFile(uri: string, flags: OPENFLAGS) : Promise<number> | --- | -- | | Promise<number> | 文件描述符 | +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + **示例:** ```js @@ -662,23 +863,29 @@ openFile(uri: string, flags: OPENFLAGS) : Promise<number> }; ``` -## FileAccessHelper.openFile +### openFile -openFile(uri: string, flags: OPENFLAGS, callback: AsyncCallback<number>) : void; +openFile(uri: string, flags: OPENFLAGS, callback: AsyncCallback<number>) : void 以异步方法打开文件,返回文件描述符。使用callback异步回调。 -**系统能力**:SystemCapability.FileManagement.UserFileService。 +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | uri | string | 是 | 待打开文件的uri | - | flags | [OPENFLAGS](#openflags) | 是 | 文件打开的标志 | - | callback | AsyncCallback<number> | 是 | 文件描述符 | +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| uri | string | 是 | 待打开文件的uri | +| flags | [OPENFLAGS](#openflags) | 是 | 文件打开的标志 | +| callback | AsyncCallback<number> | 是 | 文件描述符 | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** @@ -701,21 +908,23 @@ openFile(uri: string, flags: OPENFLAGS, callback: AsyncCallback<number>) : }; ``` -## FileAccessHelper.delete +### delete delete(uri: string) : Promise<number> 以异步方法删除文件(夹),返回错误码。使用Promise异步回调。 -**系统能力**:SystemCapability.FileManagement.UserFileService。 +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | uri | string | 是 | 待删除文件(夹)的uri | +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| uri | string | 是 | 待删除文件(夹)的uri | **返回值:** @@ -723,6 +932,10 @@ delete(uri: string) : Promise<number> | --- | -- | | Promise<number> | 删除操作的错误码 | +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + **示例:** ```js @@ -740,22 +953,28 @@ delete(uri: string) : Promise<number> }; ``` -## FileAccessHelper.delete +### delete -delete(uri: string, callback: AsyncCallback<number>) : void; +delete(uri: string, callback: AsyncCallback<number>) : void 以异步方法删除文件(夹),返回错误码。使用callback异步回调。 -**系统能力**:SystemCapability.FileManagement.UserFileService。 +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | uri | string | 是 | 待删除文件(夹)的uri | - | callback | AsyncCallback<number> | 是 | 删除操作的错误码 | +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| uri | string | 是 | 待删除文件(夹)的uri | +| callback | AsyncCallback<number> | 是 | 删除操作的错误码 | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** @@ -778,22 +997,24 @@ delete(uri: string, callback: AsyncCallback<number>) : void; }; ``` -## FileAccessHelper.move +### move move(sourceFile: string, destFile: string) : Promise<string> 以异步方法移动文件(夹),返回移动后文件(夹)的uri。使用Promise异步回调。目前仅支持设备内移动,跨设备不支持移动。 -**系统能力**:SystemCapability.FileManagement.UserFileService。 +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | sourceFile | string | 是 | 待移动的源文件(夹)的uri | - | destFile | string | 是 | 目标文件夹的uri | +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| sourceFile | string | 是 | 待移动的源文件(夹)的uri | +| destFile | string | 是 | 目标文件夹的uri | **返回值:** @@ -801,6 +1022,10 @@ move(sourceFile: string, destFile: string) : Promise<string> | ----- | ------ | | Promise<string> | 新路径下的文件(夹)的uri | +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + **示例:** ```js @@ -818,23 +1043,29 @@ move(sourceFile: string, destFile: string) : Promise<string> }; ``` -## FileAccessHelper.move +### move -move(sourceFile: string, destFile: string, callback: AsyncCallback<string>) : void; +move(sourceFile: string, destFile: string, callback: AsyncCallback<string>) : void 以异步方法移动文件(夹),返回移动后文件(夹)的uri。使用callback异步回调。目前仅支持设备内移动,跨设备不支持移动。 -**系统能力**:SystemCapability.FileManagement.UserFileService。 +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | sourceFile | string | 是 | 待移动的源文件(夹)的uri | - | destFile | string | 是 | 目标文件夹的uri | - | callback | AsyncCallback<string> | 是 | 新路径下的文件(夹)的uri | +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| sourceFile | string | 是 | 待移动的源文件(夹)的uri | +| destFile | string | 是 | 目标文件夹的uri | +| callback | AsyncCallback<string> | 是 | 新路径下的文件(夹)的uri | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** @@ -858,22 +1089,24 @@ move(sourceFile: string, destFile: string, callback: AsyncCallback<string> }; ``` -## FileAccessHelper.rename +### rename rename(uri: string, displayName: string) : Promise<string> 以异步方法重命名文件(夹),返回重命名后的文件(夹)的Uri。使用Promise异步回调。 -**系统能力**:SystemCapability.FileManagement.UserFileService。 +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | uri | string | 是 | 源文件(夹)的uri | - | displayName | string | 是 | 文件(夹)名,支持带后缀 | +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| uri | string | 是 | 源文件(夹)的uri | +| displayName | string | 是 | 文件(夹)名,支持带后缀 | **返回值:** @@ -881,6 +1114,10 @@ rename(uri: string, displayName: string) : Promise<string> | --- | -- | | Promise<string> | 重命名后的文件(夹)的uri | +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + **示例:** ```js @@ -897,23 +1134,29 @@ rename(uri: string, displayName: string) : Promise<string> }; ``` -## FileAccessHelper.rename +### rename -rename(uri: string, displayName: string, callback: AsyncCallback<string>) : void; +rename(uri: string, displayName: string, callback: AsyncCallback<string>) : void 以异步方法重命名文件(夹),返回重命名后的文件(夹)的Uri。使用callback异步回调。 -**系统能力**:SystemCapability.FileManagement.UserFileService。 +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | uri | string | 是 | 源文件(夹)的uri | - | displayName | string | 是 | 文件(夹)名,支持带后缀 | - | callback | AsyncCallback<string> | 是 | 重命名后的文件(夹)的uri | +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| uri | string | 是 | 源文件(夹)的uri | +| displayName | string | 是 | 文件(夹)名,支持带后缀 | +| callback | AsyncCallback<string> | 是 | 重命名后的文件(夹)的uri | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** @@ -936,21 +1179,23 @@ rename(uri: string, displayName: string, callback: AsyncCallback<string>) }; ``` -## FileAccessHelper.access +### access access(sourceFileUri: string) : Promise<boolean> 以异步方法判断文件(夹)是否存在。使用Promise异步回调。 -**系统能力**:SystemCapability.FileManagement.UserFileService。 +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | sourceFileUri | string | 是 | 文件(夹)的uri | +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| sourceFileUri | string | 是 | 文件(夹)的uri | **返回值:** @@ -958,6 +1203,10 @@ access(sourceFileUri: string) : Promise<boolean> | --- | -- | | Promise<boolean> | 文件(夹)是否存在 | +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 + **示例:** ```js @@ -977,22 +1226,28 @@ access(sourceFileUri: string) : Promise<boolean> }; ``` -## FileAccessHelper.access +### access -access(sourceFileUri: string, callback: AsyncCallback<boolean>) : void; +access(sourceFileUri: string, callback: AsyncCallback<boolean>) : void 以异步方法判断文件(夹)是否存在。使用callback异步回调。 -**系统能力**:SystemCapability.FileManagement.UserFileService。 +**模型约束**:此接口仅可在Stage模型下使用。 + +**系统能力**:SystemCapability.FileManagement.UserFileService **需要权限**:ohos.permission.FILE_ACCESS_MANAGER **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | sourceFileUri | string | 是 | 文件(夹)的uri | - | callback | AsyncCallback<boolean> | 是 | 文件(夹)是否存在 | +| 参数名 | 类型 | 必填 | 说明 | +| --- | --- | --- | -- | +| sourceFileUri | string | 是 | 文件(夹)的uri | +| callback | AsyncCallback<boolean> | 是 | 文件(夹)是否存在 | + +**错误码:** + +接口抛出错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 **示例:** @@ -1018,74 +1273,6 @@ access(sourceFileUri: string, callback: AsyncCallback<boolean>) : void; }; ``` -## RootIterator.next - -next( ) : { value: RootInfo, done: boolean } - -RootIterator表示设备根目录的迭代器对象,可以通过next同步方法获取下一级设备根目录。 - -**系统能力**:SystemCapability.FileManagement.UserFileService。 - -**需要权限**:ohos.permission.FILE_ACCESS_MANAGER - -**返回值:** - -| 类型 | 说明 | -| --- | -- | -| {value: RootInfo, done: boolean} | 通过next遍历文件夹,直到done返回true结束;value字段返回rootInfo。| - -## FileIterator.next - -next( ) : { value: FileInfo, done: boolean } - -FileIterator表示文件夹的迭代器对象,可以通过next同步方法获取下一级文件(夹)信息。 - -**系统能力**:SystemCapability.FileManagement.UserFileService。 - -**需要权限**:ohos.permission.FILE_ACCESS_MANAGER - -**返回值:** - -| 类型 | 说明 | -| --- | -- | -| {value: FileInfo, done: boolean} | 通过next遍历文件夹,直到done返回true结束;value字段返回fileInfo。| - -## RootInfo - -表示设备的根属性信息和接口能力。 - -**系统能力**:SystemCapability.FileManagement.UserFileService。 - -**需要权限**:ohos.permission.FILE_ACCESS_MANAGER - -### 属性 - -| 名称 | 类型 | 可读 | 可写 | 说明 | -| ------ | ------ | -------- | ------ | -------- | -| deviceType | number | 是 | 否 |设备类型 | -| uri | string | 是 | 否 | 设备根目录Uri | -| displayName | string | 是 | 否 | 设备名称 | -| deviceFlags | number | 是 | 否 | 设备支持的能力 | - -## FileInfo - -表示文件(夹)属性信息和接口能力。 - -**系统能力**:SystemCapability.FileManagement.UserFileService。 - -**需要权限**:ohos.permission.FILE_ACCESS_MANAGER - -### 属性 - -| 名称 | 类型 | 可读 | 可写 | 说明 | -| ------ | ------ | -------- | ------ | -------- | -| uri | string | 是 | 否 | 文件(夹)的uri | -| fileName | string | 是 | 否 | 文件(夹)的名称 | -| mode | number | 是 | 否 | 文件(夹)的权限信息 | -| size | number | 是 | 否 | 文件(夹)的大小 | -| mtime | number | 是 | 否 | 文件(夹)的修改时间 | -| mimeType | string | 是 | 否 | 文件(夹)的媒体资源类型 | - ## OPENFLAGS 目前支持的文件打开的标志位。 diff --git a/zh-cn/application-dev/reference/apis/js-apis-fileShare.md b/zh-cn/application-dev/reference/apis/js-apis-fileShare.md index bf8700d75f..7c37ba3ad4 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-fileShare.md +++ b/zh-cn/application-dev/reference/apis/js-apis-fileShare.md @@ -3,7 +3,8 @@ 该模块提供文件分享能力,提供系统应用将公共目录文件统一资源标志符(Uniform Resource Identifier,URI)以读写权限授权给其他应用的接口,授权后应用可通过[@ohos.file.fs](js-apis-file-fs.md)的相关接口进行相关open、read、write等操作,实现文件分享。 > **说明:** -> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +> +> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 ## 导入模块 @@ -16,8 +17,11 @@ import fileShare from '@ohos.fileShare'; grantUriPermission(uri: string, bundleName: string, mode: number, callback: AsyncCallback<void>): void 对公共目录文件URI进行授权操作,使用callback异步回调。 + **需要权限**:ohos.permission.WRITE_MEDIA + **系统接口**:此接口为系统接口 + **系统能力**:SystemCapability.FileManagement.AppFileService **参数:** @@ -31,15 +35,14 @@ grantUriPermission(uri: string, bundleName: string, mode: number, callback: Asyn **错误码:** -以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md#错误码适配指导) - - | 错误码ID | 错误信息 | - | ---------------------------- | ---------- | - | 201 | Permission verification failed | - | 202 | The caller is not a system application | - | 401 | The input parameter is invalid | - | 143000001 | IPC error | +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md) +| 错误码ID | 错误信息 | +| ---------------------------- | ---------- | +| 201 | Permission verification failed | +| 202 | The caller is not a system application | +| 401 | The input parameter is invalid | +| 143000001 | IPC error | **示例:** @@ -62,14 +65,16 @@ try { } ``` - ## fileShare.grantUriPermission grantUriPermission(uri: string, bundleName: string, mode: number): Promise<void> 将公共目录文件URI进行授权操作,使用Promise异步回调。 + **需要权限**:ohos.permission.WRITE_MEDIA + **系统接口**:此接口为系统接口 + **系统能力**:SystemCapability.FileManagement.AppFileService **参数:** @@ -86,18 +91,16 @@ grantUriPermission(uri: string, bundleName: string, mode: number): Promise<vo | ---------------------------- | ---------- | | Promise<void> | Promise对象,无返回值 | - **错误码:** -以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md#错误码适配指导) - - | 错误码ID | 错误信息 | - | ---------------------------- | ---------- | - | 201 | Permission verification failed | - | 202 | The caller is not a system application | - | 401 | The input parameter is invalid | - | 143000001 | IPC error | +以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。 +| 错误码ID | 错误信息 | +| ---------------------------- | ---------- | +| 201 | Permission verification failed | +| 202 | The caller is not a system application | +| 401 | The input parameter is invalid | +| 143000001 | IPC error | **示例:** @@ -116,4 +119,4 @@ try { } catch (error) { console.error("grantUriPermission failed with error:" + error); } - ``` \ No newline at end of file + ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-userFileManager.md b/zh-cn/application-dev/reference/apis/js-apis-userFileManager.md index b952f9bc52..d4630b1829 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-userFileManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-userFileManager.md @@ -2,9 +2,10 @@ 该模块提供用户数据管理能力,包括访问、修改用户等用户公共媒体数据信息等常用功能。 -> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 -> 本模块接口为系统接口。 +> **说明:** +> +> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +> - 本模块接口为系统接口。 ## 导入模块 @@ -19,10 +20,10 @@ getUserFileMgr(context: Context): UserFileManager 获取用户数据管理模块的实例,用于访问和修改用户等用户公共媒体数据信息(如音频、视频、图片、文档等)。 **模型约束:** 此接口仅可在Stage模型下使用。 - + **系统能力**:SystemCapability.FileManagement.UserFileManager.Core -**参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | @@ -48,11 +49,8 @@ let mgr = userFileManager.getUserFileMgr(context); getPhotoAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; - 获取图片和视频资源,使用callback方式返回结果。 - - **系统能力**:SystemCapability.FileManagement.UserFileManager.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO @@ -91,7 +89,6 @@ async function example() { } ``` - ### getPhotoAssets getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; @@ -108,7 +105,7 @@ getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>&g | ------- | ------------------- | ---- | ---------------- | | options | [FetchOptions](#fetchoptions) | 是 | 图片和视频检索选项 | -**返回值** +**返回值:** | 类型 | 说明 | | --------------------------- | -------------- | @@ -140,6 +137,7 @@ async function example() { } } ``` + ### createPhotoAsset createPhotoAsset(displayName: string, albumUri: string, callback: AsyncCallback<FileAsset>): void; @@ -234,7 +232,7 @@ createPhotoAsset(displayName: string, albumUri?: string): Promise<FileAsset&g | displayName | string | 是 | 创建的图片或者视频文件名 | | albumUri | string | 否 | 创建的图片或者视频所在相册的uri | -**返回值** +**返回值:** | 类型 | 说明 | | --------------------------- | -------------- | @@ -260,7 +258,6 @@ async function example() { getPhotoAlbums(options: AlbumFetchOptions, callback: AsyncCallback<FetchResult<Album>>): void; - 获取相册,使用callback方式返回结果。 **系统能力**:SystemCapability.FileManagement.UserFileManager.Core @@ -319,7 +316,7 @@ getPhotoAlbums(options: AlbumFetchOptions): Promise<FetchResult<Album>& | -------- | ------------------------ | ---- | ------------------------- | | options | [AlbumFetchOptions](#albumfetchoptions) | 是 | 相册检索选项 | -**返回值** +**返回值:** | 类型 | 说明 | | --------------------------- | -------------- | @@ -351,7 +348,6 @@ async function example() { getPrivateAlbum(type: PrivateAlbumType, callback: AsyncCallback<FetchResult<PrivateAlbum>>): void; - 获取系统相册,使用 callback 方式返回系统相册的数组。 **系统能力**:SystemCapability.FileManagement.UserFileManager.Core @@ -398,7 +394,7 @@ getPrivateAlbum(type: PrivateAlbumType): Promise<FetchResult<PrivateAlbum& | -------- | ------------------------ | ---- | ------------------------- | | type | [PrivateAlbumType](#privatealbumtype) | 是 | 系统相册类型 | -**返回值** +**返回值:** | 类型 | 说明 | | --------------------------- | -------------- | @@ -423,7 +419,6 @@ async function example() { getAudioAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; - 获取音频文件,使用callback方式返回结果。 **系统能力**:SystemCapability.FileManagement.UserFileManager.Core @@ -468,7 +463,6 @@ async function example() { getAudioAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; - 获取音频文件,使用callback方式返回结果。 **系统能力**:SystemCapability.FileManagement.UserFileManager.Core @@ -481,7 +475,7 @@ getAudioAssets(options: FetchOptions): Promise<FetchResult<FileAsset>&g | -------- | ------------------------ | ---- | ------------------------- | | options | [FetchOptions](#fetchoptions) | 是 | 检索选项 | -**返回值** +**返回值:** | 类型 | 说明 | | --------------------------- | -------------- | @@ -514,6 +508,7 @@ async function example() { } } ``` + ### delete delete(uri: string, callback: AsyncCallback<void>): void; @@ -563,6 +558,7 @@ async function example() { }); } ``` + ### delete delete(uri: string): Promise<void>; @@ -579,7 +575,7 @@ delete(uri: string): Promise<void>; | -------- | ------------------------- | ---- | ---------- | | uri | string | 是 | 媒体文件uri | -**返回值**: +**返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | @@ -1092,7 +1088,6 @@ open(mode: string, callback: AsyncCallback<number>): void **需要权限**:ohos.permission.READ_IMAGEVIDEO 或 ohos.permission.READ_AUDIO 或 ohos.permission.WRITE_IMAGEVIDEO 或 ohos.permission.WRITE_AUDIO - **系统能力**:SystemCapability.FileManagement.UserFileManager.Core **参数** @@ -1482,7 +1477,7 @@ getCount(): number **系统能力**:SystemCapability.FileManagement.UserFileManager.Core -**返回值**: +**返回值:** | 类型 | 说明 | | ------ | -------- | @@ -1514,7 +1509,7 @@ isAfterLast(): boolean **系统能力**:SystemCapability.FileManagement.UserFileManager.Core -**返回值**: +**返回值:** | 类型 | 说明 | | ------- | ---------------------------------- | @@ -1618,7 +1613,7 @@ getFirstObject(): Promise<T> **系统能力**:SystemCapability.FileManagement.UserFileManager.Core -**返回值**: +**返回值:** | 类型 | 说明 | | --------------------------------------- | -------------------------- | @@ -1690,7 +1685,7 @@ async function example() { **系统能力**:SystemCapability.FileManagement.UserFileManager.Core -**返回值**: +**返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | @@ -1762,7 +1757,7 @@ getLastObject(): Promise<T> **系统能力**:SystemCapability.FileManagement.UserFileManager.Core -**返回值**: +**返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | @@ -1838,7 +1833,7 @@ getPositionObject(index: number): Promise<T> | ----- | ------ | ---- | -------------- | | index | number | 是 | 要获取的文件的索引,从0开始 | -**返回值**: +**返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | @@ -1922,6 +1917,7 @@ async function example() { }); } ``` + ### getPhotoAssets getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; @@ -2015,7 +2011,7 @@ commitModify(): Promise<void>; **系统能力**:SystemCapability.FileManagement.UserFileManager.Core -**返回值**: +**返回值:** | 类型 | 说明 | | ------------------- | ------------ | @@ -2105,6 +2101,7 @@ async function example() { } ``` + ### getPhotoAssets getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; @@ -2121,7 +2118,7 @@ getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>&g | -------- | ------------------------- | ---- | ---------- | | options | [FetchOptions](#fetchoptions) | 是 | 检索选项 | -**返回值**: +**返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | @@ -2146,6 +2143,7 @@ async function example() { console.info('fetchResult.count = ', count); } ``` + ### delete delete(uri: string, callback: AsyncCallback<void>): void; @@ -2189,6 +2187,7 @@ async function example() { }); } ``` + ### delete delete(uri: string): Promise<void>; @@ -2205,7 +2204,7 @@ delete(uri: string): Promise<void>; | -------- | ------------------------- | ---- | ---------- | | uri | string | 是 | 相册uri | -**返回值**: +**返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | @@ -2279,6 +2278,7 @@ async function example() { }); } ``` + ### recover recover(uri: string): Promise<void>; @@ -2295,7 +2295,7 @@ recover(uri: string): Promise<void>; | -------- | ------------------------- | ---- | ---------- | | uri | string | 是 | 相册uri | -**返回值**: +**返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | @@ -2331,12 +2331,12 @@ async function example() { 成员类型。 **系统能力:** 以下各项对应的系统能力均为SystemCapability.FileManagement.UserFileManager.Core - + | 名称 | 类型 | 可读 | 可写 | 说明 | | ----- | ---- | ---- | ---- | ---- | -| number | number | 是 | 是 | number类型 | -| string | string | 是 | 是 | string类型 | -| boolean | boolean | 是 | 是 | boolean类型 | +| number | number | 是 | 是 | number类型 | +| string | string | 是 | 是 | string类型 | +| boolean | boolean | 是 | 是 | boolean类型 | ## ChangeEvent @@ -2365,7 +2365,6 @@ async function example() { | networkId | string | 是 | 否 | 注册设备的网络ID | | isOnline | boolean | 是 | 否 | 是否在线 | - ## FileType 枚举,媒体文件类型。 @@ -2389,8 +2388,6 @@ async function example() { | TYPE_FAVORITE | 0 | 收藏夹相册 | | TYPE_TRASH | 1 | 回收站相册 | - - ## AudioKey 枚举,音频文件关键信息。 @@ -2444,7 +2441,6 @@ async function example() { | DATE_ADDED | date_added | 添加日期(添加文件时间到1970年1月1日的秒数值) | | DATE_MODIFIED | date_modified | 修改日期(修改文件时间到1970年1月1日的秒数值,修改文件名不会改变此值,当文件内容发生修改时才会更新) | - ## FetchOptions 检索条件。 @@ -2465,4 +2461,3 @@ async function example() { | 名称 | 类型 | 可读 | 可写 | 说明 | | ---------------------- | ------------------- | ---- |---- | ------------------------------------------------ | | predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md) | 是 | 是 | 谓词查询,显示过滤条件 | - diff --git a/zh-cn/application-dev/reference/errorcodes/errorcode-filemanagement.md b/zh-cn/application-dev/reference/errorcodes/errorcode-filemanagement.md index 3c68d9eb0a..976d9b9749 100644 --- a/zh-cn/application-dev/reference/errorcodes/errorcode-filemanagement.md +++ b/zh-cn/application-dev/reference/errorcodes/errorcode-filemanagement.md @@ -4,7 +4,7 @@ > > 以下仅介绍本模块特有错误码,通用错误码请参考[通用错误码说明文档](errorcode-universal.md)。 -文件管理子系统错误码由四部分组成,分别是基础文件IO错误码、用户数据管理错误码、公共文件访问错误码和空间统计错误码组成。 +文件管理子系统错误码由四部分组成,分别是[基础文件IO错误码](#基础文件io错误码)、[用户数据管理错误码](#用户数据管理错误码)、[公共文件访问错误码](#公共文件访问错误码)和[空间统计错误码](#空间统计错误码)组成。 ## 基础文件IO错误码 @@ -719,41 +719,3 @@ Fail to notify agent **处理步骤** 检查client是否异常 - -## 错误码适配指导 -文件管理子系统API支持异常处理。 -同步接口异常处理示例代码: -```js -import fs from '@ohos.file.fs' - -try { - let file = fs.openSync(path, fs.OpenMode.READ_ONLY); -} catch (err) { - console.error("openSync errCode:" + err.code + ", errMessage:" + err.message); -} -``` -异步接口promise方法异常处理示例代码: -```js -import fs from '@ohos.file.fs' - -try { - let file = await fs.open(path, fs.OpenMode.READ_ONLY); -} catch (err) { - console.error("open promise errCode:" + err.code + ", errMessage:" + err.message); -} -``` - -异步接口callback方法异常处理示例代码: -```js -import fs from '@ohos.file.fs' - -try { - fs.open(path, fs.OpenMode.READ_ONLY, function(e, file){ //异步线程的错误(如系统调用等)在回调中获取 - if (e) { - console.error("open in async errCode:" + e.code + ", errMessage:" + e.message); - } - }); -} catch (err) { //主线程的错误(如非法参数等)通过try catch获取 - console.error("open callback errCode:" + err.code + ", errMessage:" + err.message); -} -``` -- GitLab