# Read and Write data from text file

**URL:** <https://forums.unrealengine.com/t/read-and-write-data-from-text-file/291916>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [August 24, 2014, 8:59pm UTC](https://forums.unrealengine.com/t/read-and-write-data-from-text-file/291916 "2014-08-24T20:59:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_adc3f730](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_adc3f730](https://forums.unrealengine.com/u/anonymous_user_adc3f730)\
**Post date:** [August 24, 2014, 8:59pm UTC](https://forums.unrealengine.com/t/read-and-write-data-from-text-file/291916/1 "2014-08-24T20:59:33Z")

</div>

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 😕

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [August 24, 2014, 9:27pm UTC](https://forums.unrealengine.com/t/read-and-write-data-from-text-file/291916/2 "2014-08-24T21:27:38Z")

</div>

#CoreMisc.h

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

```
FFileHelper::SaveStringToFile(...);

FFileHelper::LoadANSITextFileToStrings(...);

```

#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](https://forums.unrealengine.com/showthread.php?3851-(39)-Rama-s-Extra-Blueprint-Nodes-for-You-as-a-Plugin-No-C-Required)!

Enjoy!

Rama

---

<div class="post-metadata">

**Author:** ![Hayaweh](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Hayaweh](https://forums.unrealengine.com/u/Hayaweh)\
**Post date:** [October 12, 2014, 1:19pm UTC](https://forums.unrealengine.com/t/read-and-write-data-from-text-file/291916/3 "2014-10-12T13:19:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Eymrich](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Eymrich](https://forums.unrealengine.com/u/Eymrich)\
**Post date:** [June 15, 2016, 11:37am UTC](https://forums.unrealengine.com/t/read-and-write-data-from-text-file/291916/4 "2016-06-15T11:37:40Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f82846a8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f82846a8](https://forums.unrealengine.com/u/anonymous_user_f82846a8)\
**Post date:** [June 18, 2016, 3:02pm UTC](https://forums.unrealengine.com/t/read-and-write-data-from-text-file/291916/5 "2016-06-18T15:02:50Z")

</div>

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 ?

Thank!

---

<div class="post-metadata">

**Author:** ![Xanitsu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Xanitsu](https://forums.unrealengine.com/u/Xanitsu)\
**Post date:** [August 17, 2016, 2:14pm UTC](https://forums.unrealengine.com/t/read-and-write-data-from-text-file/291916/6 "2016-08-17T14:14:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lillydr1scoll](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lillydr1scoll](https://forums.unrealengine.com/u/lillydr1scoll)\
**Post date:** [January 18, 2019, 12:07pm UTC](https://forums.unrealengine.com/t/read-and-write-data-from-text-file/291916/7 "2019-01-18T12:07:35Z")

</div>

Yes it still work

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5e132e2c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5e132e2c](https://forums.unrealengine.com/u/anonymous_user_5e132e2c)\
**Post date:** [February 5, 2019, 11:08pm UTC](https://forums.unrealengine.com/t/read-and-write-data-from-text-file/291916/8 "2019-02-05T23:08:18Z")

</div>

These C++ commands are now found in:

**\> Core/Public/Misc/FileHelper**
