C# File ReadAllBytes
Description
File ReadAllBytes
Opens a binary file, reads the contents
of the file into a byte array, and then closes the file.
Syntax
File.ReadAllBytes
has the following syntax.
public static byte[] ReadAllBytes(
string path
)
Parameters
File.ReadAllBytes
has the following parameters.
path
- The file to open for reading.
Returns
File.ReadAllBytes
method returns
Example
Opens a file, reads the contents of the file into a byte array, and then closes the file.
/* w w w. ja v a 2 s . c o m*/
using System;
using System.IO;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
string[] createText = { "Hello", "And", "java2s.com" };
File.WriteAllLines(path, createText);
byte[] readText = File.ReadAllBytes(path);
foreach (byte s in readText)
{
Console.WriteLine(s);
}
}
}