如何读取文本文件(txt)中的中文汉字
在线等!

解决方案 »

  1.   

    StreamReader sr = new StreamReader(path, Encoding.GetEncode("gb2312"));
    string line = sr.ReadLine();如上代码可读取gb2312编码的文本。
      

  2.   

    参考:
    //读取文本文件,注意设置此文件的访问权限
    FileStream fs = new FileStream("e:\\通知.txt", FileMode.Open);
    byte[] bytes = new byte[(int)fs.Length];
    fs.Read(bytes, 0, bytes.Length);
    fs.Close();
    strNews = System.Text.Encoding.GetEncoding("gb2312").GetString(bytes);
    strNews=strNews.Replace("\r","<br>");
    strNews=strNews.Replace("\0","&nbsp;&nbsp;");
    strNews=strNews.Replace("\t","&nbsp;&nbsp;&nbsp;&nbsp;");
    strNews=strNews.Replace(" ","&nbsp;&nbsp;"); //html 下
    <MARQUEE onmouseover="this.stop()" style="BORDER-RIGHT: dimgray thin; BORDER-TOP: dimgray thin solid; Z-INDEX: 101; LEFT: 40px; BORDER-LEFT: dimgray thin; WIDTH: 780px; COLOR: green; BORDER-BOTTOM: dimgray thin solid; POSITION: absolute; TOP: 80px; HEIGHT: 468px; TEXT-DECORATION: none"
    onmouseout="this.start()" scrollAmount="3" scrollDelay="80" direction="up" behavior="scroll">
    <%=strNews%>  //读取strNews
    </MARQUEE>
      

  3.   

    就是注意一下编码问题。
    用System.Text.Encoding.Default或Encoding.GetEncode("gb2312")都行。
      

  4.   

    stream = new StreamReader(filename,System.Text.Encoding.Default);