Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


OpenRead(string)

Opens a file for reading, resolving logical paths automatically.
Read time 1 minuteLast updated 7 days ago

Definition

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

Parameters

path

Path to the file. Accepts logical and physical paths.

Returns

Type

Description

StreamA read-only Stream over the file content. Dispose the stream when finished.

Remarks

Returns a readable Stream for the file at
path
. Unlike
File.Open
, this method accepts logical paths directly without first converting them with FileUtil.PathToAbsolutePath.
Throws ArgumentException when
path
is null or empty. Throws IOException when the file cannot be opened.

Examples

using System.IO;using UnityEditor;using UnityEngine;public class OpenReadExample{ [MenuItem("Example/Read File As Stream")] static void ReadAsStream() { using (Stream stream = FileUtil.OpenRead("Packages/com.example.package/Resources/config.bytes")) using (var reader = new BinaryReader(stream)) { int version = reader.ReadInt32(); Debug.Log("Config version: " + version); } }}