ReadAllBytes(string)
Opens a binary file, reads the contents of the file into a byte array, and then closes the file.
Read time 1 minuteLast updated 5 days ago
Definition
- Type: Method
- Namespace: UnityEngine.Windows
- Assembly: UnityEngine.CoreModule
public static byte[] ReadAllBytes(string path)
Parameters
Complete path of the file to open for reading.
Returns
Type | Description |
|---|---|
| byte[] | Managed array of bytes of the complete file content. |
Remarks
If the file is not found, the function returns an empty array of bytes ( size=0 ).
Examples
var filePath = "path_to_your_file/yourfile.dat";// Check if the file existsif (File.Exists(filePath)){ // Read the entire file into a byte array var fileData = File.ReadAllBytes(filePath); // Output the size of the file Debug.Log($"File size: {fileData.Length} bytes");}else{ Debug.LogError($"File not found at path: {filePath}");}