zoukankan      html  css  js  c++  java
  • VB2005读取文本文件乱码的解决方法

    在VB2005中,至少可以通过两种常规的方法实现快速读写文本文件,第一种是通过streamReader对象
    如以下代码

            Try
                  Using sr 
    As StreamReader = New StreamReader("c:\aa.txt", Encoding.Default)
                    
    Dim line As String

                    
    Do
                        line 
    = sr.ReadLine
                        Console.WriteLine(line)
                    
    Loop Until line Is Nothing
                    sr.Close()
                
    End Using
            
    Catch Ex As Exception
                Console.WriteLine(
    "The file could not be read:")
                Console.WriteLine(Ex.Message)
            
    End Try
    如果你没有在第二行中构造函数的第二个参数设置为Encoding.Default,你读入的中文文本将是乱码,原因是vs2005为适应新的操作系统,在语言支持上默认为英文标准,
    另外一种方法是通过MY.Computer.FileSystem,如 
    dim sr as system.io.streamReader
    sr=my.computer.filesystem.openTextfileReader("c:\aa.txt") 把全部文本取回
     这个对象的很多属性,方法的使用更是方便简单,这里不做累赘
  • 相关阅读:
    园 首页 新随笔 联系 管理 订阅 订阅 RTSP协议转换RTMP直播协议
    sequence diagram
    Model Binding
    asp.net mvc
    系统日志和异常的处理①
    随机森林之oob error 估计
    Extjs相关知识点梳理
    Extjs报错处理
    webbrowser在html中写入内容并添加js
    tcpdump一个命令的剖析
  • 原文地址:https://www.cnblogs.com/same/p/585932.html
Copyright © 2011-2022 走看看