首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

急vb.net生成TXT资料编码是ANSI

2012-09-10 
急!vb.net生成TXT文件编码是ANSIvb.net生成TXT文件,我这里生成的是UTF-8,在别的机器打开是乱码,要求为ANSI

急!vb.net生成TXT文件编码是ANSI
vb.net生成TXT文件,我这里生成的是UTF-8,在别的机器打开是乱码,要求为ANSI,如何解决,代码如下:

VB.NET code
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk        'Dim filepath As String = OpenFileDialog1.FileName        'Dim stremreaderreges As StreamReader = File.OpenText(filepath)        'Me.RichTextBox1.Text = stremreaderreges.ReadToEnd()        'stremreaderreges.Close()        Dim filepath As String = OpenFileDialog1.FileName        Dim readtext() As String = File.ReadAllLines(filepath, Encoding.GetEncoding("GB2312"))        Dim s As String        Dim j As Integer = 0        Dim k As Integer = 1        Dim str() As String        Dim str2(5) As String        Dim amount As Double        Dim filename As String        amount = 0        For Each s In readtext            str = Split(s, " ")            amount = amount + str(UBound(str) - 1)        '统计总金额        Next        Dim createtext(UBound(readtext) + 2) As String        createtext(0) = "S,000191400100172," + Format(Now(), "yyyyMMdd") + "," + (UBound(readtext) + 1).ToString + "," + (amount * 100).ToString + ",10600"        For Each s In readtext            str = Split(s, " ")            j = 0            For i = 0 To UBound(str)                If Len(Trim(str(i))) > 0 Then                    str2(j) = str(i)                    j = j + 1                End If            Next            createtext(k) = k.ToString + "," + str2(4) + ",103,," + str2(2) + "," + str2(1) + ",河北,,,," + (str2(3) * 100).ToString + ",,,,,,,," + str2(0) + ",,"            k = k + 1        Next        If My.Computer.FileSystem.DirectoryExists("d:\去盘文件") = False Then            My.Computer.FileSystem.CreateDirectory("d:\去盘文件")        End If        filename = "d:\去盘文件\000191400100172_S02" + Format(Now(), "yyyyMMdd") + "_000001.txt"        File.WriteAllLines(filename, createtext)        MessageBox.Show("去盘文件已经生成!")    End Sub


[解决办法]
http://topic.csdn.net/u/20090514/00/42a608e5-1589-4c45-a185-cf57f43fc916.html
[解决办法]
File.WriteAllLines(filename, createtext,Encoding.GetEncoding("GB2312"))
[解决办法]
Encoding.Default
不同的系统结果是不同的

热点排行