From 7afd6cefb4abe8dda4643ac02678dba8435ea6cf Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Sat, 28 Sep 2024 20:22:55 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E5=88=A4=E6=96=AD=E6=96=87?= =?utf8?q?=E4=BB=B6=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E7=9A=84=E7=BB=9F?= =?utf8?q?=E4=B8=80=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../uicomponents/UIComponents.cpp | 10 ++++++++++ .../CustomUIComponentTool/uicomponents/UIComponents.h | 2 ++ 2 files changed, 12 insertions(+) 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 -- 2.17.1