专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

openfiledialog打开的文件显示乱码解决办法

发布时间:2011-06-23 16:02:53 文章来源:www.iduyao.cn 采编人员:星星草
openfiledialog打开的文件显示乱码
Public Class dialogs
  Private strfilename As String

  Private Sub btnopen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnopen.Click
  With OpenFileDialog1
  .Filter = "text document(*.txt)|*.txt|all file(*.txt)|*.*"
  .FilterIndex = 1
  .Title = " demo open file dialog"
  End With
  If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

   
  Try
  strfilename = OpenFileDialog1.FileName
  Dim fileContents As String
  fileContents = My.Computer.FileSystem.ReadAllText(strfilename)
  txtfile.Text = fileContents
  Catch ex As Exception
  MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
  End Try
  End If
  End Sub


End Class
打开的文本文件是乱码 是怎么回事 啊??

------解决方案--------------------
在ReadAllText方法的FILENAME参数后面指定ENCODING
------解决方案--------------------
ls的意思是
fileContents = My.Computer.FileSystem.ReadAllText(strfilename)
改成
fileContents = My.Computer.FileSystem.ReadAllText(strfilename, System.Text.Encoding.Default)
测试文本文件通过
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: