string msg = "dhgfjdbghafj";
byte[] myByte = System.Text.Encoding.UTF8.GetBytes(msg);
//向流中写入信息
using (FileStream fsWrite = new FileStream(@"D:111.txt", FileMode.OpenOrCreate, FileAccess.Write))
{
fsWrite.Write(myByte,0,myByte.Length);
}
//读文件
using (FileStream fsRead = new FileStream(@"D:111.txt", FileMode.OpenOrCreate, FileAccess.Read))
{
int mylength = (int)fsRead.Length;
byte[] heByte = new byte[mylength];
int r = fsRead.Read(heByte,0,heByte.Length);
string myStr = System.Text.Encoding.UTF8.GetString(heByte);
Console.Write(myStr);
Console.ReadKey();
}