1# @ohos.file.fileuri (文件URI) 2 3该模块提供通过PATH获取文件统一资源标志符(Uniform Resource Identifier,URI),后续可通过使用[@ohos.file.fs](js-apis-file-fs.md)进行相关open、read、write等操作,实现文件分享。 4 5> **说明:** 6> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 7 8## 导入模块 9 10```js 11import fileuri from "@ohos.file.fileuri"; 12``` 13 14使用该功能模块前,需要先获取其应用沙箱路径,开发示例如下: 15 16 ```js 17import UIAbility from '@ohos.app.ability.UIAbility'; 18 19export default class EntryAbility extends UIAbility { 20 onWindowStageCreate(windowStage) { 21 let context = this.context; 22 let pathDir = context.filesDir; 23 } 24} 25 ``` 26 27## fileUri.getUriFromPath 28 29getUriFromPath(path: string): string 30 31以同步方法获取文件URI。 32 33**系统能力**:SystemCapability.FileManagement.AppFileService 34 35**参数:** 36 37| 参数名 | 类型 | 必填 | 说明 | 38| ------ | ------ | ---- | -------------------------- | 39| path | string | 是 | 文件的沙箱路径 | 40 41**返回值:** 42 43 | 类型 | 说明 | 44 | ---------------------------- | ---------- | 45 | string | 返回文件URI | 46 47**错误码:** 48 49以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md#错误码适配指导) 50 | 错误码ID | 错误信息 | 51 | ---------------------------- | ---------- | 52 | 401 | The input parameter is invalid | 53 54 55**示例:** 56 57 ```js 58let filePath = pathDir + "test.txt"; 59let uri = fileuri.getUriFromPath(filePath); 60 ``` 61