请问如何用FileStream打开一个*.txt文件,为什么我打开中文显示乱码? 看这个FAQ,一般是因为编码的问题。http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=26533 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 FileStream fs = new FileStream("c:\\aaa.txt", FileMode.Open);byte[] bytes = new byte[(int)fs.Length];fs.Read(bytes, 0, bytes.Length);fs.Close();string s = System.Text.Encoding.GetEncoding("gb2312").GetString(bytes);MessageBox.Show(s); string str; string address=""; FileStream fs; try { fs=new FileStream("setip.hcl",FileMode.OpenOrCreate); } catch(FileNotFoundException ex) { MessageBox.Show("读取文件出现错误!"+ex.Message,"错误",0x00); return; } StreamReader sr=new StreamReader(fs); while((str=sr.ReadLine())!=null) { address=address+str; } sr.Close(); StreamReader sr=new StreamReader(path,System.Text.Encoding.Default) 怎么实现这个功能 都夜的第七章了,(第七张贴)困惑。。。 使用c#模拟登陆一个jsp页面 100分提问,.net 压缩文件 请教一个基础问题:几种类型转换有什么区别?请高人给个详解。 客户端一开机,服务器就能获得他的mac地址,请问用.net怎么写 众家所核! 救急 关于comboBox控件的简单问题(请大家帮忙,高分) 关于vs c# textbox禁用的问题 我看来具难问题??(用户自定义web界面和数据库表)!给点意见。 jmail收信问题。
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
string s = System.Text.Encoding.GetEncoding("gb2312").GetString(bytes);
MessageBox.Show(s);
string address="";
FileStream fs;
try
{
fs=new FileStream("setip.hcl",FileMode.OpenOrCreate);
}
catch(FileNotFoundException ex)
{
MessageBox.Show("读取文件出现错误!"+ex.Message,"错误",0x00);
return;
}
StreamReader sr=new StreamReader(fs); while((str=sr.ReadLine())!=null)
{
address=address+str;
} sr.Close();