vb.net 创建与读取文本文件的方法

下面是创建代码:

        If File.Exists("C:\abc.txt") Then
            File.Delete("C:\abc.txt")
        End If
        Dim sr As StreamWriter = File.CreateText("C:\abc.txt")
        sr.Write("晨彦电脑科技")
        sr.WriteLine("WWW.BTOSS.COM")
        sr.Write("这是一个创建文本文件的例子")
        sr.Close()

下面是读取代码:


        If File.Exists("C:\abc.txt") = False Then
            MsgBox("文件不存在!")
        Else
            Dim sr As StreamReader = File.OpenText("C:\abc.txt")
            Dim str As String = sr.ReadLine
            Dim i As Integer = 0
            While Not IsNothing(str)
                i = i + 1
                If i = 1 Then
                    Me.TextBox1.Text &= str
                Else
                    Me.TextBox1.Text &= "," + str
                End If

                str = sr.ReadLine
            End While
        End If
订阅评论
提醒

Captcha Code

0 评论
最旧
最新 最多投票
0
希望看到您的想法,请您发表评论x