1# Accessing Application Files (C/C++) 2<!--Kit: Core File Kit--> 3<!--Subsystem: FileManagement--> 4<!--Owner: @wangke25; @gsl_1234; @wuchengjun5--> 5<!--Designer: @gsl_1234; @wangke25--> 6<!--Tester: @liuhonggang123; @yue-ye2; @juxiaopang--> 7<!--Adviser: @foryourself--> 8 9## When to Use 10 11The **FileIO** module provides some APIs for basic file operations. For details about other APIs, see [libc](../reference/native-lib/musl.md) and [libc++](../reference/native-lib/cpp.md). 12 13## Constraints 14 15Before performing file operations, ensure that the URI or path passed in is correct and valid. 16 17## Available APIs 18 19For details about the APIs, see [FileIO](../reference/apis-core-file-kit/capi-oh-fileio-h.md). 20 21| API| Description| 22| -------- | -------- | 23| FileManagement_ErrCode OH_FileIO_GetFileLocation(char *uri, int uriLength, FileIO_FileLocation *location)| Obtains the location of a file.| 24| enum FileIO_FileLocation FileIO_FileLocation| Enumerates the file locations.| 25| enum FileManagement_ErrCode FileManagement_ErrCode| Enumerates the error codes used in the **FileIO** module.| 26 27## How to Develop 28 29**Adding the Dynamic Link Library** 30 31Add the following library to **CMakeLists.txt**. 32 33```txt 34target_link_libraries(sample PUBLIC libohfileio.so) 35``` 36 37**Adding the Header File** 38 39```c++ 40#include <cstdio> 41#include <cstring> 42#include <filemanagement/fileio/oh_fileio.h> 43``` 44 45Call **OH_FileIO_GetFileLocation** to obtain the location of a file. <br>Example: 46```c 47void GetFileLocationExample() { 48 char *uri = "file://com.example.demo/data/storage/el2/base/files/test.txt"; 49 FileIO_FileLocation location; 50 FileManagement_ErrCode ret = OH_FileIO_GetFileLocation(uri, strlen(uri), &location); 51 if (ret == 0) { 52 if (location == FileIO_FileLocation::LOCAL) { 53 printf("This file is on local."); 54 } else if (location == FileIO_FileLocation::CLOUD) { 55 printf("This file is on cloud."); 56 } else if (location == FileIO_FileLocation::LOCAL_AND_CLOUD) { 57 printf("This file is both on local and cloud."); 58 } 59 } else { 60 printf("GetFileLocation failed, error code is %d", ret); 61 } 62} 63``` 64