// 大概是这样,还没测试过,应该没问题吧
string FullPathFileName = "我的文件.txt";
FileInfo fi = new FileInfo( FullPathFileName );
System.IO.FileStream fs = fi.OpenRead();
byte[] cont = new byte[ fs.Length ];
fs.Read( cont , 0 , cont.Length );
fs.Close();
StreamWriter docWriter;
System.Text.Encoding ec = System.Text.Encoding.GetEncoding( "UTF-8" );
System.Text.Encoding ecGB2312 = System.Text.Encoding.GetEncoding( "GB2312" );
docWriter = new StreamWriter( new FileStream( FullPathFileName , FileMode.CreateNew ) , ec );
docWriter.Write( ecGB2312.GetString( cont ));
docWriter.Close();
谢谢你的豆子阿
gb2312改成utd-8有啥用吗 ?貌似没多大区别的啊!
String str=new String("1234.csv".getBytes("gb2312"),"utf-8");
我只是打个比喻,我是要把国外文档的编码格式转换为UTF-8,不然老是乱码。
String str=new String("1234.csv".getBytes("gb2312"),"utf-8");
你这样只是把"1234.csv"当成一个字符串把"1234.csv"转换编码格式吧,而不是改变文件打开的编码格式
保存的时候指定编码:
new StreamWriter("...", false, System.Text.Encoding.UTF8)