※ 引述《chienyu (充實自己)》之銘言:
: 請問一下
: 在VB2005裡讀取txt檔案
: txt檔案裡是打中文
: 但是執行後,Combobox裡卻顯示亂碼,EX: 口口口口口 (原文為:大屁屁)
: 程式碼如下
: Dim f As New FileInfo(Application.StartupPath + "\combolist.txt")
: Dim sr As StreamReader = f.OpenText
: Do While sr.Peek >= 0
: ComboBox7.Items.Add(sr.ReadLine)
: Loop
: sr.Close()
: 請問這是哪裡出了問題呢@_@?
: 還是說這是轉碼的問題?
FileInfo.OpenWrite 應該也是使用 UTF-8 編碼,所以可以讀取。
使用指定編碼讀取:
Using reader As New StreamReader(檔案路徑 , System.Text.Encoding.Default)
'讀取檔案
End Using
建立 StreamWrite 也類似這樣。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.160.69.234