注册 登录
编程论坛 VB.NET论坛

(已经解决)敬请各位高手解决vb.net(vs2010)如何使读取TXT文件能正常显示汉字的问题。谢谢。

HVB6 发布于 2017-06-26 09:32, 1893 次点击
以下代码是打开(vs2010)→新建项目→双击新建按钮:(以下代码是一次性读取TXT文件内容,
但显示汉字为乱码如何解决?逐行读取TXT文件内容且能显示汉字的代码已经有,不在此讨论。)
Imports
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s As String
        s = "f:\rat.txt"
        Dim file As New (s)
        Dim words As String = file.ReadToEnd()
        file.Close()
        MsgBox(words)
    End Sub
End Class
只有本站会员才能查看附件,请 登录



[此贴子已经被作者于2017-6-26 11:02编辑过]

1 回复
#2
shsmhq2017-06-26 10:41
        Dim s As String
        s = "f:\rat.txt"
        Dim file As New (s, System.Text.Encoding.GetEncoding("GB2312")) '这一句需要给字体编码,简体中文编码为GB2312
        Dim words As String = file.ReadToEnd
        file.Close()
        MsgBox(words)
1