|
网上不少类似的代码都没有考虑编码格式,导致读取中文时会乱码,这份代码读取中文文件时不会乱码!
- Imports System.IO
- '参数:文件名
- Public Function EasyReadFile(ByVal f As String) As String
- Dim objFile As New System.IO.StreamReader(f, System.Text.Encoding.Default)
- Dim sz As String = objFile.ReadToEnd()
- objFile.Close()
- objFile.Dispose()
- Return sz
- End Function
- '参数:文件名, 内容
- Public Sub EasyWriteFile(ByVal f As String, ByVal s As String)
- Dim sw As StreamWriter = New StreamWriter(f, False, System.Text.Encoding.Default)
- sw.Write(s)
- sw.Flush()
- sw.Close()
- End Sub
复制代码 |
|