none
VB。NET 中STEAMREADER 问题 RRS feed

  • 问题

  •  

    Imports System
    Imports System.IO
    Public Class Form1

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim a As New FileStream("d:\d.txt", FileMode.Open)
            Dim c As New FileStream("C:\Documents and Settings\sxm\桌面\b.txt", FileMode.Open)
            Dim b As New StreamReader(c)
            Dim x As New StreamWriter(a)
            Dim d As String
            While b.Peek <> -1
                d = b.ReadLine()
                x.Write(d)
                TextBox1.Text &= b.ReadLine() & vbCrLf
            End While
            x.Close()
            a.Close()
            b.Close()
            c.Close()
        End Sub
    End Class

     

     

    C:\Documents and Settings\sxm\桌面\b.txt中有英文和中文内容

    我在界面上是一个BUTTON 和TEXTBOX空件 运行后在d:\d.txt中输出的是中文乱码

    英文到可以输出来 

    怎样才能输出中文来 请高手解救下

    2008年6月1日 6:06

答案

  • Code Snippet

     

    Dim b As New  StreamReader("C:\Documents and Settings\sxm\桌面\b.txt", System.Text.Encoding.GetEncoding("GB2312"))

     

     

    Dim x As New  StreamWriter("C:\Documents and Settings\sxm\桌面\b.txt", System.Text.Encoding.GetEncoding("GB2312"))

    不要使用FileStream就可以 了

     

     

     

    2008年6月1日 8:04
    版主