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

FileUtil.ReadAllBytes

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

Parameters

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

Returns

byte[] The entire file content as a byte array.

Description

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

Reads and returns all bytes in the file at path. Unlike File.ReadAllBytes, 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.OpenRead, FileUtil.ReadAllText, FileUtil.ReadAllLines

using UnityEditor;
using UnityEngine;

public class ReadAllBytesExample { [MenuItem("Example/Read File Bytes")] static void ReadFileBytes() { byte[] data = FileUtil.ReadAllBytes("Packages/com.example.package/Resources/data.bytes"); Debug.Log("Read " + data.Length + " bytes."); } }