您的位置:首页 > 编程语言 > C#

c#读取文件乱码问题

2007-05-16 15:34 417 查看
//获取文件的路径
this.textBox3.Text=this.openFileDialog1.FileName;

//读去文件到文本筐中
try
{
if(!File.Exists(this.textBox3.Text.Trim()))
{
MessageBox.Show("wenjianbucunzai");
}
else
{
//打开文件流
FileStream fs=File.OpenRead(this.textBox3.Text.Trim());

//创建一个byte数组读取
byte[] arr=new byte[fs.Length];

UTF8Encoding datautf=new UTF8Encoding(true);
if(arr.Length>0)
{
fs.Read(arr,0,arr.Length);

this.textBox4.Text=datautf.GetString(arr);

fs.Close();
}

}
}
catch(IOException ex)
{
ex.StackTrace.ToString();
}

为什么读出来的文本是乱码?(中文是这样)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: