VB.net 文件读取、写入、追加操作

前端之家收集整理的这篇文章主要介绍了VB.net 文件读取、写入、追加操作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Dim PathUserData As String = Application.StartupPath & "\实操统计sql.txt"
TextTB.Text = System.IO.File.ReadAllText(PathUserData)
‘或者用 System.IO.File.ReadAllText(PathUserData,System.Text.Encoding.UTF8)
上面这个是读取

System.IO.File.ReadAllText(PathUserData,System.Text.Encoding.UTF8) 此用法是把编码方式转为UTF8



写入如下:

        Dim PathUserData As String = Application.StartupPath & "\实操统计sql.txt"
        Dim t As System.IO.StreamWriter = New System.IO.StreamWriter(PathUserData,True,System.Text.Encoding.UTF8)
        t.Write(TextTB.Text)
        t.Close()


追加如下:

        Dim PathUserData As String = Application.StartupPath & "\实操统计sql.txt"
        Dim t As System.IO.StreamWriter = New System.IO.StreamWriter(PathUserData,System.Text.Encoding.UTF8)
        t.WriteLine(TextTB.Text)
        t.Close()

同样的,你可以把
System.Text.Encoding.UTF8
去掉或者保留

猜你在找的VB相关文章