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

FileUtil.ReadAllLines

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[] ReadAllLines(string path);

Parameters

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

Returns

string[] An array containing one element per line. Lines are split on \r\n and \n.

Description

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

Reads the entire file at path and returns its lines as a string array. Unlike File.ReadAllLines, 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.ReadAllText, FileUtil.ReadAllBytes, FileUtil.OpenRead

using UnityEditor;
using UnityEngine;

public class ReadAllLinesExample { [MenuItem("Example/Read File Lines")] static void ReadFileLines() { string[] lines = FileUtil.ReadAllLines("Packages/com.example.package/Resources/manifest.txt"); foreach (string line in lines) Debug.Log(line); } }