2020年9月3日 星期四

Vb.net 讀寫到txt檔 (Function) [Write Read txt File (Function)]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    Private Sub write2txt(ByVal strPath As String, ByVal strInfo As String)
        Dim FileWriter As StreamWriter

        'Dim encFormat As Encoding
        'encFormat = Encoding.Default
        'FileWriter = New StreamWriter(strPath, False, encFormat)

        FileWriter = New StreamWriter(strPath, False)
        FileWriter.Write(strInfo)
        FileWriter.Close()
    End Sub




 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
    Private Function read4txt(ByVal strPath As String) As String
        If File.Exists(strPath) = True Then
            Dim FileReader As StreamReader
            Dim strInfo As String

            'Dim encFormat As Encoding
            'encFormat = Encoding.Default
            'FileReader = New StreamReader(strPath, encFormat)

            FileReader = New StreamReader(strPath)
            strInfo = FileReader.ReadToEnd()
            FileReader.Close()
            Return strInfo
        End If
    End Function

沒有留言:

張貼留言