harmony 鸿蒙Accessing Application Files (C/C++)
Accessing Application Files (C/C++)
When to Use
The FileIO module provides some APIs for basic file operations. For details about other APIs, see libc and libc++.
Basic Concepts
URI: uniquely identifies a file.
Constraints
Before performing file operations, ensure that the URI or path passed in is correct and valid.
Available APIs
For details about the APIs, see FileIO.
API | Description |
---|---|
FileManagement_ErrCode OH_FileIO_GetFileLocation(char *uri, int uriLength, FileIO_FileLocation *location) | Obtains the location of a file. |
enum FileIO_FileLocation FileIO_FileLocation | Enumerates the file locations. |
enum FileManagement_ErrCode FileManagement_ErrCode | Enumerates the error codes used in the FileIO module. |
How to Develop
Adding the Dynamic Link Library
Add the following library to CMakeLists.txt.
target_link_libraries(sample PUBLIC libohfileio.so)
Adding the Header File
#include <cstdio>
#include <cstring>
#include <filemanagement/fileio/oh_fileio.h>
Call OH_FileIO_GetFileLocation to obtain the location of a file.
Example:
void GetFileLocationExample() {
char *uri = "file://com.example.demo/data/storage/el2/base/files/test.txt";
FileIO_FileLocation location;
FileManagement_ErrCode ret = OH_FileIO_GetFileLocation(uri, strlen(uri), &location);
if (ret == 0) {
if (location == FileIO_FileLocation::LOCAL) {
printf("This file is on local.");
} else if (location == FileIO_FileLocation::CLOUD) {
printf("This file is on cloud.");
} else if (location == FileIO_FileLocation::LOCAL_AND_CLOUD) {
printf("This file is both on local and cloud.");
}
} else {
printf("GetFileLocation failed, error code is %d", ret);
}
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Accessing Application Files (ArkTS)
harmony 鸿蒙Accessing Backup and Restore
harmony 鸿蒙Application Data Backup and Restore Overview
harmony 鸿蒙Backup and Restore Triggered by System Applications
harmony 鸿蒙Application File Overview
harmony 鸿蒙Obtaining Application and File System Space Statistics
harmony 鸿蒙Introduction to Core File Kit
harmony 鸿蒙Developing a File Manager Application (for System Applications Only)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦