C# File WriteAllBytes

Description

File WriteAllBytes 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 overwritten.

Syntax

File.WriteAllBytes has the following syntax.


public static void WriteAllBytes(
  string path,
  byte[] bytes
)

Parameters

File.WriteAllBytes has the following parameters.

  • path - The file to write to.
  • bytes - The bytes to write to the file.

Returns

File.WriteAllBytes method returns

Example


/*from ww w  . j  a  va 2s .co  m*/
using System;
using System.IO;

class Program
{
  static void Main(string[] args)
  {
    File.WriteAllBytes(@"C:\temp\new.txt", new byte[]{1,2,3});

  }

}




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter