Returns the contents of a file as a byte array.
' Usage Dim value As Byte() = My.Computer.FileSystem.ReadAllBytes(file) ' Declaration Public Function ReadAllBytes( _ ByVal file As String _ ) As Byte()
The following conditions may cause an exception to be thrown:
The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; or it is a device path (starts with \\.\) (ArgumentException).
The file name ends with a trailing slash (ArgumentException).
The path is not valid because it is Nothing (ArgumentNullException).
The file does not exist (FileNotFoundException).
The file is in use by another process or an I/O error occurs (IOException).
The path exceeds the system-defined maximum length (PathTooLongException).
A file or directory name in the path contains a colon (:) or is in an invalid format (NotSupportedException).
There is not enough memory to write the string to buffer (OutOfMemoryException).
The user lacks necessary permissions to view the path (SecurityException).
The ReadAllBytes method of the My.Computer.FileSystem object allows you to read from a binary file. The contents of the file are returned as a byte array.
Do not make decisions about the contents of the file based on the name of the file. For example, the file Form1.vb may not be a Visual Basic source file. Verify all inputs before using the data in your application.
The following table lists examples of tasks involving the My.Computer.FileSystem.ReadAllBytes method.
Read from a binary file
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
Availability by Project Type
Windows Control Library
Web Control Library