From: Caisking <3449750381@qq.com> Date: Sat, 28 Sep 2024 12:22:55 +0000 (+0800) Subject: 增加判断文件是否存在的统一接口 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=fad74e90c920377d49e086361b80ff972d509603;p=mirrors%2FFD230.git 增加判断文件是否存在的统一接口 --- diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp index 800087976..cfb778daf 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp @@ -9,6 +9,10 @@ #include #include #include +#include +#include +#include + namespace OHOS { @@ -911,5 +915,11 @@ namespace OHOS path.c_str()); } } + + // 检查文件是否可打开并且不为空 + bool IsFileAccessibleAndNotEmpty(const std::string& filePath) { + std::ifstream file(filePath); + return file.is_open() && file.peek() != std::ifstream::traits_type::eof(); + } } diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h index 41dccf9c3..1b28230ca 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h @@ -306,6 +306,8 @@ namespace OHOS void CreateDirectoryIfNotExists(const std::string &path); + bool IsFileAccessibleAndNotEmpty(const std::string& filePath); + #endif } // namespace OHOS