當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET FileInfo.AppendText方法代碼示例

本文整理匯總了VB.NET中System.IO.FileInfo.AppendText方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET FileInfo.AppendText方法的具體用法?VB.NET FileInfo.AppendText怎麽用?VB.NET FileInfo.AppendText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.FileInfo的用法示例。


在下文中一共展示了FileInfo.AppendText方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Test

' 導入命名空間
Imports System.IO

Public Class Test

    Public Shared Sub Main()
        Dim fi As FileInfo = New FileInfo("c:\temp\MyTest.txt")
        Dim sw As StreamWriter

        ' This text is added only once to the file.
        If fi.Exists = False Then
            'Create a file to write to.
            sw = fi.CreateText()
            sw.WriteLine("Hello")
            sw.WriteLine("And")
            sw.WriteLine("Welcome")
            sw.Flush()
            sw.Close()
        End If

        ' This text will always be added, making the file longer over time
        ' if it is not deleted.
        sw = fi.AppendText()

        sw.WriteLine("This")
        sw.WriteLine("is Extra")
        sw.WriteLine("Text")
        sw.Flush()
        sw.Close()

        'Open the file to read from.
        Dim sr As StreamReader = fi.OpenText()
        Dim s As String
        Do While sr.Peek() >= 0
            s = sr.ReadLine()
            Console.WriteLine(s)
        Loop
        sr.Close()
    End Sub
End Class
'This code produces output similar to the following; 
'results may vary based on the computer/file structure/etc.:
'
'Hello
'And
'Welcome
'This
'is Extra
'Text
開發者ID:VB.NET開發者,項目名稱:System.IO,代碼行數:49,代碼來源:FileInfo.AppendText

輸出:

Hello
And
Welcome
This
is Extra
Text
This
is Extra
Text

示例2: AppendTextTest

' 導入命名空間
Imports System.IO

Public Class AppendTextTest
    Public Shared Sub Main()
        Dim fi As New FileInfo("temp.txt")
        Dim sw As StreamWriter = fi.AppendText()
        sw.WriteLine("Add as many lines as you like...")
        sw.WriteLine("Add another line to the output...")
        sw.Flush()
        sw.Close()
        Dim sr As New StreamReader(fi.OpenRead())
        ' Get the information out of the file and display it.
        ' Remember that the file might have other lines if it already existed.
        While sr.Peek() <> -1
            Console.WriteLine(sr.ReadLine())
        End While
    End Sub
End Class
'This code produces output similar to the following;
'results may vary based on the computer/file structure/etc.:
'Add as many lines as you like...
'Add another line to the output...
開發者ID:VB.NET開發者,項目名稱:System.IO,代碼行數:23,代碼來源:FileInfo.AppendText


注:本文中的System.IO.FileInfo.AppendText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。