提交 82dc919d 编写于 作者: 1 18721213663

add_fileuri

Signed-off-by: N18721213663 <zhuhongtao12@huawei.com>
上级 e0ad198b
...@@ -40,6 +40,70 @@ export default class EntryAbility extends UIAbility { ...@@ -40,6 +40,70 @@ export default class EntryAbility extends UIAbility {
FA模型context的具体获取方法参见[FA模型](js-apis-inner-app-context.md#Context模块) FA模型context的具体获取方法参见[FA模型](js-apis-inner-app-context.md#Context模块)
## FileUri<sup>10+</sup>
### 属性
**系统能力**:SystemCapability.FileManagement.AppFileService
| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| path<sup>10+</sup> | string | 是 | 否 | 获取FileUri对应路径名 |
| name<sup>10+</sup> | string | 是 | 否 | 获取FileUri对应文件名 |
### constructor<sup>10+</sup>
constructor(uriOrPath: string)
constructor是FileUri的构造函数。
**系统能力:** SystemCapability.FileManagement.AppFileService
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| uriOrPath | string | 是 | uri或路径。uri类型:<br/>-&nbsp; 应用沙箱URI:file://\<bundleName>/\<sandboxPath> <br/>-&nbsp; 公共目录文件类URI:file://docs/storage/Users/currentUser/\<publicPath> <br/>-&nbsp; 公共目录媒体类URI:file://media/\<mediaType>/IMG_DATATIME_ID/\<displayName> |
**错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- |
| 13900005 | I/O error |
| 13900042 | Unknown error |
**示例:**
```js
let path = pathDir + '/test';
let uri = fileuri.getUriFromPath(filePath); // file://<packageName>/data/storage/el2/base/haps/entry/files/test
let fileUriObject = new fileuri.FileUri(uri);
console.info("The name of FileUri is " + fileUriObject.name);
```
### toString<sup>10+</sup>
toString(): string
**系统能力:** SystemCapability.FileManagement.AppFileService
返回字符串类型uri。
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| string | 返回字符串类型uri |
**示例:**
```js
let path = pathDir + '/test';
let fileUriObject = new fileuri.FileUri(path);
console.info("The uri of FileUri is " + fileUriObject.toString());
```
## fileUri.getUriFromPath ## fileUri.getUriFromPath
getUriFromPath(path: string): string getUriFromPath(path: string): string
......
...@@ -533,6 +533,41 @@ copyDir(src: string, dest: string, mode?: number, callback: AsyncCallback\<void> ...@@ -533,6 +533,41 @@ copyDir(src: string, dest: string, mode?: number, callback: AsyncCallback\<void>
}); });
``` ```
## fs.dup<sup>10+</sup>
dup(fd: number): File
将文件描述符转化为File。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | --------------------------- |
| fd | number | 是 | 文件描述符。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| [File](#file) | 打开的File对象。 |
**错误码:**
接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)
**示例:**
```js
// convert fd to file
let fd = 0; // fd comes from other modules
let file = fs.dup(fd);
console.info("The name of the file is " + file.name);
fs.closeSync(file);
```
## fs.mkdir ## fs.mkdir
mkdir(path: string): Promise&lt;void&gt; mkdir(path: string): Promise&lt;void&gt;
...@@ -3263,6 +3298,8 @@ readSync(buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): ...@@ -3263,6 +3298,8 @@ readSync(buffer: ArrayBuffer, options?: { offset?: number; length?: number; }):
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ---- | ------ | ---- | ---- | ------- | | ---- | ------ | ---- | ---- | ------- |
| fd | number | 是 | 否 | 打开的文件描述符。 | | fd | number | 是 | 否 | 打开的文件描述符。 |
| path<sup>10+</sup> | string | 是 | 否 | 文件路径。 |
| name<sup>10+</sup> | string | 是 | 否 | 文件名。 |
### lock ### lock
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册