File.AppendText Method Creates a StreamWriter and appends UTF-8 encoded text to the file. : Stream Writer « File Directory « VB.Net






File.AppendText Method Creates a StreamWriter and appends UTF-8 encoded text to the file.

 

Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
        Dim path As String = "c:\temp\MyTest.txt"
        Dim sw As StreamWriter

        If File.Exists(path) = False Then
            sw = File.CreateText(path)
            sw.WriteLine("A")
            sw.WriteLine("B")
            sw.WriteLine("C")
            sw.Flush()
            sw.Close()
        End If
        sw = File.AppendText(path)
        sw.WriteLine("D")
        sw.WriteLine("E")
        sw.WriteLine("F")
        sw.Flush()
        sw.Close()

        Dim sr As StreamReader = File.OpenText(path)
        Dim s As String
        Do While sr.Peek() >= 0
            s = sr.ReadLine()
            Console.WriteLine(s)
        Loop
        sr.Close()
    End Sub
End Class

   
  








Related examples in the same category

1.StreamWriter WriteLine
2.StreamWriter Implements a TextWriter for writing characters to a stream in a particular encoding.
3.StreamWriter.Write (Char[], Int32, Int32) writes a subarray of characters to the stream.
4.Cookie class is used to manage cookies
5.Cookie.Comment Property gets or sets a comment that the server can add to a Cookie.
6.StreamReader.CurrentEncoding Property gets character encoding
7.StreamReader.Peek Method Returns the next available character but does not consume it.
8.StreamReader.ReadLine Method reads a line of characters from the current stream
9.StreamReader.ReadToEnd reads stream from the current position to the end
10.Create StreamWriter from file name string
11.Create StreamWriter from FileStream
12.Create StreamWriter from FileStream and default encoding
13.New StreamWriter("FileName", True)
14.Create FileStream from file name string
15.Create StreamWriter with Encoding UTF8
16.Create StreamWriter with Encoding UTF8 and buffer size
17.Writes a subarray of characters to the stream with StreamWriter
18.Creates a StreamWriter and write text to it
19.Flush data to StreamWriter
20.Write Unicode char with StreamWriter
21.StreamWriter Class Implements a TextWriter for writing characters to a stream in a particular encoding.
22.Use StreamWriter to write text to a file