1.新建一个c++ 文件,类型为BlueprintFunctionLibrary

RWTextFile.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "RWTextFile.generated.h"

/**
 * 
 */
UCLASS()
class CEXPAND_API URWTextFile : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
public:
	UFUNCTION(BlueprintPure, Category = "Custom", meta = (Keywords = "LoadTxt"))
		static bool LoadText(FString FileName, FString& OutText);

	UFUNCTION(BlueprintCallable, Category = "Custom", meta = (Keywords = "SaveTxt"))
		static bool SaveText(FString InText, FString FileName);
	
};

RWTextFile.cpp

// Fill out your copyright notice in the Description page of Project Settings.

#include "RWTextFile.h"
#include "Runtime/Core/Public/Misc/FileHelper.h"
#include "Runtime/Core/Public/Misc/Paths.h"



bool URWTextFile::LoadText(FString FileNameA, FString& SaveTextA){
	return FFileHelper::LoadFileToString(SaveTextA,*(FPaths::GameDir()+FileNameA)) ;
}


bool URWTextFile::SaveText(FString SaveTextB, FString FileNameB)
{
	return FFileHelper::SaveStringToFile(FileNameB,*(FPaths::GameDir()+FileNameB));
}

2 在项目的根目录下新建一个文件
UE4_读写内容到文本文件

3 蓝图调用代码截图如下:
UE4_读写内容到文本文件

相关文章:

  • 2022-12-23
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-12-12
  • 2021-11-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案