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

定义

打开一个二进制文件,将文件的内容读入一个字节数组,然后关闭该文件。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()

参数

path
String String String String

要打开以进行读取的文件。The file to open for reading.

返回

Byte[]

包含文件内容的字节数组。A byte array containing the contents of the file.

异常

path 是一个长度为零的字符串,仅包含空格,或包含一个或多个由 InvalidPathChars 定义的无效字符。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).

打开文件时发生 I/O 错误。An I/O error occurred while opening the file.

当前平台不支持此操作。This operation is not supported on the current platform.

- 或 --or- path 指定了一个目录。path specified a directory.

- 或 --or- 调用方没有所要求的权限。The caller does not have the required permission.

未找到 path 中指定的文件。The file specified in path was not found.

path 的格式无效。path is in an invalid format.

调用方没有所要求的权限。The caller does not have the required permission.

注解

根据文件路径,此方法将打开该文件,文件的内容读入一个字节数组,,然后关闭该文件。Given a file path, this method opens the file, reads the contents of the file into a byte array, and then closes the file.

安全性

FileIOPermission
用于读取文件或目录的访问。for access to read from a file or directory. 关联的枚举: ReadAssociated enumeration: Read

适用于

另请参阅