| Parameter | Description |
|---|---|
| path | Path to the file. Accepts logical and physical paths. |
Stream A read-only System.IO.Stream over the file content. Dispose the stream when finished.
Opens a file for reading, resolving logical paths automatically.
Returns a readable System.IO.Stream for the file at path. Unlike File.Open, this method accepts logical paths directly without first converting them with FileUtil.PathToAbsolutePath.
Throws System.ArgumentException when path is null or empty.
Throws System.IO.IOException when the file cannot be opened.
Additional resources: FileUtil.ReadAllBytes, FileUtil.ReadAllText, FileUtil.ReadAllLines, FileUtil.PathToAbsolutePath
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); } } }