File.ReadAllBytes(String) File.ReadAllBytes(String) File.ReadAllBytes(String) File.ReadAllBytes(String) Method

Definition

Opens a binary file, reads the contents of the file into a byte array, and then closes the file.

public:
 static cli::array <System::Byte> ^ ReadAllBytes(System::String ^ path);
public static byte[] ReadAllBytes (string path);
static member ReadAllBytes : string -> byte[]
Public Shared Function ReadAllBytes (path As String) As Byte()
Parameters
path
String String String String

The file to open for reading.

Returns
Byte[]

A byte array containing the contents of the file.

Exceptions

path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.

The specified path, file name, or both exceed the system-defined maximum length.

The specified path is invalid (for example, it is on an unmapped drive).

An I/O error occurred while opening the file.

This operation is not supported on the current platform.

-or-

path specified a directory.

-or-

The caller does not have the required permission.

The caller does not have the required permission.

Remarks

Given a file path, this method opens the file, reads the contents of the file into a byte array, and then closes the file.

Security

FileIOPermission
for access to read from a file or directory. Associated enumeration: Read

Applies to