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 to the file. Accepts logical and physical paths.
Returns
Type | Description |
|---|---|
| Stream | A read-only Stream over the file content. Dispose the stream when finished. |
Remarks
Returns a readable Stream for the file at . Unlike , this method accepts logical paths directly without first converting them with FileUtil.PathToAbsolutePath.
pathFile.OpenThrows ArgumentException when is null or empty. Throws IOException when the file cannot be opened.
pathAdditional Resources: FileUtil.ReadAllBytes, FileUtil.ReadAllText, FileUtil.ReadAllLines, FileUtil.PathToAbsolutePath
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); } }}