Read and Write data from text file

Is it possible to read and write data from a text file for example use the text files data ( exampletext ) and store it as a variable Player->Name = file; out put = hello, exampletext

if that is understandable :confused:


All the functionality you want is in CoreMisc.h

	 * Write the FString to a file.
	 * Supports all combination of ANSI/Unicode files and platforms.
	static bool SaveStringToFile( const FString& String, const TCHAR* Filename, EEncodingOptions::Type EncodingOptions=EEncodingOptions::AutoDetect, IFileManager* FileManager=&IFileManager::Get() );

	 * Load a text file to an FString.
	 * Supports all combination of ANSI/Unicode files and platforms.
	 * @param Result string representation of the loaded file
	 * @param Filename name of the file to load
	 * @param VerifyFlags flags controlling the hash verification behavior ( see EHashOptions )
	static bool LoadFileToString( FString& Result, const TCHAR* Filename, uint32 VerifyFlags=0 );

	 *	Load the given ANSI text file to an array of strings - one FString per line of the file.
	 *	Intended for use in simple text parsing actions
	 *	@param	InFilename			The text file to read, full path
	 *	@param	InFileManager		The filemanager to use - NULL will use &IFileManager::Get()
	 *	@param	OutStrings			The array of FStrings to fill in
	 *	@return	bool				true if successful, false if not
	static bool LoadANSITextFileToStrings(const TCHAR* InFilename, IFileManager* InFileManager, TArray<FString>& OutStrings);

#Sample Usage:

You call the functions statically



#CPP Source Code For You

I use the above functions in my Victory BP Library plugin, whose entire source code is available with the download (no cost)

(39) Rama's Extra Blueprint Nodes for You as a Plugin, No C++ Required! - Blueprint - Unreal Engine Forums!



thanks a lot. This is exactly what I was searching for! :slight_smile:
(and that’s quite an impressive work you made, congrats) :slight_smile:

Just want to add that the WriteFlags refered from FFileHelper::SaveStringToFile can be found(i think/hope) in FileManager.h :

enum EFileWrite
    FILEWRITE_NoFail            = 0x01,
    FILEWRITE_NoReplaceExisting = 0x02,
    FILEWRITE_EvenIfReadOnly    = 0x04,
    FILEWRITE_Append			= 0x08,
    FILEWRITE_AllowRead			= 0x10

The default behaviour is rewrite the file with the Fstring. If you want to add Fstring to the same file you will make a call with 0x08 inside the flags. Remember that the new line is LINE_TERMINATOR and you should be ready to go!
Hope can be useful, being almost a total newbie to Unreal c++ this could saved me some time :slight_smile:

Hi !

I trying to write it to the text file from UE4 version 4.11. Does this method still work on it ? If yes , how ?


Yes it does you would use the “file IO save string array to file” node. It also works with 4.12 and 4.13 (i think). I am not sure how to read the files though.

Yes it still work

These C++ commands are now found in:

> Core/Public/Misc/FileHelper