FileStream afile = new FileStream (Singlefile, FileMode.Open); StreamReader sr = new StreamReader (Afile, encoding.getencoding ("gb2312"), true); string filecontent = Sr. ReadToEnd (); Afile.close (); ProcessData Pd = new ProcessData (); Pd.procedata (filecontent);
StreamReader using 3 parameters The last automatic detection utf-8, Chinese is mostly gb2312, if not utf-8, use gb2312
The system comes with UTF detection, see the following
private void detectencoding () {if (This.bytelen >= 2) {this._detectencoding = false; BOOL flag = FALSE; if ((this.bytebuffer[0] = = 0xFE) && (this.bytebuffer[1] = = 0xff)) {this.encoding = new Unicodee Ncoding (True, true); This.compressbuffer (2); Flag = true; } else if ((this.bytebuffer[0] = = 0xff) && (this.bytebuffer[1] = = 0xFE)) {if ((this.byt ELen < 4) | | (this.bytebuffer[2]! = 0)) || (this.bytebuffer[3]! = 0)) {this.encoding = new UnicodeEncoding (false, True); This.compressbuffer (2); Flag = true; } else {this.encoding = new UTF32Encoding (false, True); This.compressbuffer (4); Flag = true; }} else if (((This.bytelen >= 3) && (this.bytebuffer[0] = = 0xEF)) && ((this.bytebuffer[1 ] = = 0XBB)&& (this.bytebuffer[2] = = 0XBF)) {this.encoding = Encoding.UTF8; This.compressbuffer (3); Flag = true; } else if ((((This.bytelen >= 4) && (this.bytebuffer[0] = = 0)) && ((this.bytebuffer[1] = = 0) &am p;& (this.bytebuffer[2] = = 0xFE)) && (this.bytebuffer[3] = = 0xff)) {this.encoding = new UT F32encoding (True, true); This.compressbuffer (4); Flag = true; } else if (This.bytelen = = 2) {this._detectencoding = true; } if (flag) {This.decoder = This.encoding.GetDecoder (); This._maxcharsperbuffer = This.encoding.GetMaxCharCount (this.byteBuffer.Length); This.charbuffer = new Char[this._maxcharsperbuffer]; } }}