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