GetDataFromFile.h UCLASS() class MYPROJECT_API UGetDataFromFile : public UBlueprintFunctionLibrary{ GENERATED_BODY() public : UFUNCTION(BlueprintCallable, Category = " Data " ) static FString GetDataFromFile(FString FilePath);}; GetDataFrom
GetDataFromFile.h
UCLASS() class MYPROJECT_API UGetDataFromFile : public UBlueprintFunctionLibrary { GENERATED_BODY() public: UFUNCTION(BlueprintCallable, Category = "Data") static FString GetDataFromFile(FString FilePath); };
GetDataFromFile.cpp
#include "GetDataFromFile.h" //文件路径检索助手 #include "Runtime/Core/Public/Misc/Paths.h" FString UGetDataFromFile::GetDataFromFile(FString FilePath) { //文件路径+文件名 FString File = FPaths::ProjectContentDir() + FilePath; //返回值 FString FileContent; //判断路径下的文件是否存在 if (FPaths::FileExists(File)) { FFileHelper::LoadFileToString(FileContent, *File); return FileContent; } else return FileContent; }
测试数据:
运行结果:
问题:
中文感叹号‘!‘显示‘??‘。
解决方法:
字符编码错误导致,换成英文‘!‘。