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);
Public Shared Function ReadAllBytes (path As String) As Byte()
Parameters
path
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. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

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 file specified in path was not found.

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