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