1# 应用文件访问(C/C++) 2 3## 场景介绍 4 5FileIO模块提供了文件基础操作能力。 6 7## 基本概念 8 9**结果集**:满足使用场景正确的 uri。 10 11## 约束限制 12 13- 进行文件操作之前,必须保证传入正确有效的uri或path。 14 15## 接口说明 16 17接口的详细说明,请参考[API参考](../reference/apis-core-file-kit/_file_i_o.md) 18 19| 接口名称 | 描述 | 20| -------- | -------- | 21| FileManagement_ErrCode OH_FileIO_GetFileLocation(char *uri, int uriLength, FileIO_FileLocation *location)| 获取文件存储位置。| 22| enum FileIO_FileLocation FileIO_FileLocation| 文件存储位置枚举值。 | 23| enum enum FileManagement_ErrCode FileManagement_ErrCode| 文件管理模块错误码。| 24 25## 开发步骤 26 27**在CMake脚本中链接动态库** 28 29CMakeLists.txt中添加以下lib。 30 31```txt 32target_link_libraries(sample PUBLIC libohfileio.so) 33``` 34 35**添加头文件** 36 37```c++ 38#include <filemanagement/fileio/oh_fileio.h> 39``` 40 41调用OH_FileIO_GetFileLocation接口获取文件存储位置。示例代码如下所示: 42```c 43 void GetFileLocationExample() { 44 char *uri = "file://com.example.demo/data/storage/el2/base/files/test.txt"; 45 FileIO_FileLocation location; 46 FileManagement_ErrCode ret = OH_FileIO_GetFileLocation(uri, strlen(uri), &location); 47 if (ret == 0) { 48 if (location == FileIO_FileLocation::LOCAL) { 49 printf("This file is on local."); 50 } else if (location == FileIO_FileLocation::CLOUD) { 51 printf("This file is on cloud."); 52 } else if (location == FileIO_FileLocation::LOCAL_AND_CLOUD) { 53 printf("This file is both on local and cloud."); 54 } 55 } else { 56 printf("GetFileLocation failed, error code is %d", ret); 57 } 58 } 59 ``` 60