用记事本打开是正常的,另存为时显示是Unicode编码,用vb打开,line input读取时变成乱码,那位大侠帮我啊。

解决方案 »

  1.   

    Option ExplicitPrivate Sub Command1_Click()
        Dim filename As String
        Dim l As Long
        Dim bytearr() As Byte
        filename = "c:\mc\123.txt"
        l = FileLen(filename)
        ReDim bytearr(l - 1)
        Open filename For Binary As #1
        Get #1, , bytearr
        Close
        Dim s As String
        s = StrConv(bytearr, vbUnicode) '关键
        MsgBox s
    End Sub
      

  2.   

    line put是按照但字节读取数据的
      

  3.   

    '显示所选择的文本文件的内容,流操作,读文件
        Private Sub showtxt()
            Dim ae As New ASCIIEncoding()
            Dim str As String
            Dim str1 As String
            Dim bytes(1000) As Byte
            Dim node As TreeNode
            node = Me.TreeView1.SelectedNode
            str = getpath(node)
            fs = New FileStream(str, FileMode.Open)
            fs.BeginRead(bytes, 0, 1000, AddressOf endread, New Object())
            str1 = ae.GetString(bytes)
            Me.TextBox2.Text = str1
            If Err.Number <> 0 Then
                MsgBox("打开文件失败!")
            Else
                MsgBox("打开文件成功!")
            End If
        End Sub
        Private Sub endread(ByVal l As IAsyncResult)
            fs.EndRead(l)
            fs.Close()
        End Sub