System.IO.StreamReader sr = new StreamReader("文件名", Encoding...); string s = sr.ReadLine(); 这样读,然后换编码,看那个对就用哪个。 非内置的编码用Encoding.GetEncoding()如Encoding.GetEncoding("BIG5")
1。在读文件的时候指定系统默认字体。由于我们系统字体都是日文,所以这种办法可以实现。但是,如果换成中文字体,将无法解决。 StreamReader sr = new StreamReader(myStream,System.Text.Encoding.Default ); 缺点:不够灵活。 优点:简单 2。根据配置文件的字符集读取。 string s = "shift-jis" ;//可从配置文件中取得 StreamReader sr = new StreamReader(myStream,System.Text.Encoding.GetEncoding(s)); 缺点:需要知道字符集的字符串 优点:灵活,可扩展性强。
string s = sr.ReadLine();
这样读,然后换编码,看那个对就用哪个。
非内置的编码用Encoding.GetEncoding()如Encoding.GetEncoding("BIG5")
StreamReader sr = new StreamReader(myStream,System.Text.Encoding.Default );
缺点:不够灵活。
优点:简单
2。根据配置文件的字符集读取。
string s = "shift-jis" ;//可从配置文件中取得
StreamReader sr = new StreamReader(myStream,System.Text.Encoding.GetEncoding(s));
缺点:需要知道字符集的字符串
优点:灵活,可扩展性强。