Able to write to text file, but not read

Hello,

I followed RAMA’s tuto to read/write in txt from blueprint.
The code to write is working:

bool UFileLoaderReader::WriteToFile(FString Path, FString FileName, FString TextToSave, bool AllowOverwriting)
{
	VerifyOrCreateDirectory(Path);

	IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();

	// CreateDirectoryTree returns true if the destination
	// directory existed prior to call or has been created
	// during the call.
	if (PlatformFile.CreateDirectoryTree(*Path))
	{
		// Get absolute file path
		FString AbsoluteFilePath = Path + FileName;

		// Allow overwriting or file doesn't already exist
		if (AllowOverwriting || !PlatformFile.FileExists(*AbsoluteFilePath))
		{
			FFileHelper::SaveStringToFile(TextToSave, *AbsoluteFilePath);
			return true;
		}
	}
	return false;
}

But to read… it looks like it never get trought

if (PlatformFile.FileExists(*AbsoluteFilePath))

The function:

bool UFileLoaderReader::ReadFromFile(FString PathToFile, FString FileName, FString& Result)
{
	IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();

	// CreateDirectoryTree returns true if the destination
	// directory existed prior to call or has been created
	// during the call.
	if (PlatformFile.CreateDirectoryTree(*PathToFile))
	{
		// Get absolute file path
		FString AbsoluteFilePath = PathToFile + FileName;

		// Allow overwriting or file doesn't already exist
		if (PlatformFile.FileExists(*AbsoluteFilePath))
		{
			FFileHelper::LoadFileToString(Result, *AbsoluteFilePath);
			return true;
		}
	}
	return false;
}

little help? Thank you!
Dex

Hi!

I also read RAMA write to text file tutorial , but I could not get it to write to text file. I also tried to use your code but still cannot work. Do you know how to write to text file ?

Thank !

Hello Yanjieng,

You can use the Victory plugin (Thanks to Rama… again ^^)

You’ll find some I/O node in it, like “WriteStringToFile”.

If you want to find how to do it yourself, look it up in the source:

Or you can just download it:

You’ll find documentation about it in the Wiki:

Ciao,
Dex

Thank for the fast reply. I will try it again and let you know .