增加判断文件是否存在的统一接口
authorCaisking <3449750381@qq.com>
Sat, 28 Sep 2024 12:22:55 +0000 (20:22 +0800)
committerCaisking <3449750381@qq.com>
Sat, 28 Sep 2024 12:22:55 +0000 (20:22 +0800)
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h

index 8000879..cfb778d 100644 (file)
@@ -9,6 +9,10 @@
 #include <sys/types.h>  
 #include <fcntl.h>  
 #include <unistd.h>  
+#include <fstream>  
+#include <string>  
+#include <iostream>  
+
 
 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();  
+    }
    
 }
index 41dccf9..1b28230 100644 (file)
@@ -306,6 +306,8 @@ namespace OHOS
 
     void CreateDirectoryIfNotExists(const std::string &path);
 
+    bool IsFileAccessibleAndNotEmpty(const std::string& filePath);
+
 #endif
 
 } // namespace OHOS