Επεξεργασία

Κοινή χρήση μέσω


File.WriteAllBytes Method

Definition

Overloads

WriteAllBytes(String, Byte[])

Creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is truncated and overwritten.

WriteAllBytes(String, ReadOnlySpan<Byte>)

Creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is truncated and overwritten.

WriteAllBytes(String, Byte[])

Source:
File.cs
Source:
File.cs
Source:
File.cs

Creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is truncated and overwritten.

public:
 static void WriteAllBytes(System::String ^ path, cli::array <System::Byte> ^ bytes);
public static void WriteAllBytes (string path, byte[] bytes);
static member WriteAllBytes : string * byte[] -> unit
Public Shared Sub WriteAllBytes (path As String, bytes As Byte())

Parameters

path
String

The file to write to.

bytes
Byte[]

The bytes to write to the file.

Exceptions

.NET Framework and .NET Core versions older than 2.1: path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the GetInvalidPathChars() method.

path is null or the byte array is empty.

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.

path specified a file that is read-only.

-or-

path specified a file that is hidden.

-or-

This operation is not supported on the current platform.

-or-

path specified a directory.

-or-

The caller does not have the required permission.

path is in an invalid format.

The caller does not have the required permission.

Remarks

Given a byte array and a file path, this method opens the specified file, writes the contents of the byte array to the file, and then closes the file.

Applies to

WriteAllBytes(String, ReadOnlySpan<Byte>)

Creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is truncated and overwritten.

public:
 static void WriteAllBytes(System::String ^ path, ReadOnlySpan<System::Byte> bytes);
public static void WriteAllBytes (string path, ReadOnlySpan<byte> bytes);
static member WriteAllBytes : string * ReadOnlySpan<byte> -> unit
Public Shared Sub WriteAllBytes (path As String, bytes As ReadOnlySpan(Of Byte))

Parameters

path
String

The file to write to.

bytes
ReadOnlySpan<Byte>

The bytes to write to the file.

Exceptions

path is null.

path is empty.

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.

path specified a file that is read-only.

-or-

path specified a file that is hidden.

-or-

path specified a directory.

-or-

The caller does not have the required permission.

-or-

This operation is not supported on the current platform.

path is in an invalid format.

Applies to