文档

Unity Engine

Unity Engine

ReadAllText(string)

Reads all text from a file, resolving logical paths automatically.
阅读时间1 分钟最后更新于 1 个月前

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor.CoreModule
public static string ReadAllText(string path)

Parameters

path

Path to the file. Accepts logical and physical paths.

Returns

Type

Description

stringThe entire file content as a string.

Remarks

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 ArgumentException when
path
is null or empty.

Examples

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); }}