Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

FileUtil.ReadAllText

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static string ReadAllText(string path);

Parameters

Parameter Description
path Path to the file. Accepts logical and physical paths.

Returns

string The entire file content as a string.

Description

Reads all text from a file, resolving logical paths automatically.

Reads and returns the full text content of the file at path. Unlike File.ReadAllText, this method accepts logical paths directly without first converting them with FileUtil.PathToAbsolutePath.

Throws System.ArgumentException when path is null or empty.

Additional resources: FileUtil.ReadAllLines, FileUtil.ReadAllBytes, FileUtil.OpenRead

using UnityEditor;
using UnityEngine;

public class ReadAllTextExample { [MenuItem("Example/Read File Text")] static void ReadFileText() { string text = FileUtil.ReadAllText("Packages/com.example.package/Resources/config.json"); Debug.Log(text); } }