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

来源:互联网 发布:deepin linux 编辑:程序博客网 时间:2024/04/29 07:56
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, True, System.Text.Encoding.UTF8)        t.WriteLine(TextTB.Text)        t.Close()

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

0 0
原创粉丝点击