public static void Main()
{
string path = @"d:\MyTest1.txt";
if (!File.Exists(path))
{
// Create the file.
FileStream fs = File.Create(path);
{
Byte[] info = new UTF8Encoding(true).GetBytes("This is a file");
fs.Write(info, 0, info.Length);
}
}
using (FileStream fs = File.OpenRead(path))
{
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
while (fs.Read(b,0,b.Length) > 0)
{
Console.WriteLine(temp.GetString(b));
}
} |