VB.net Program to Append Text Into an Already Existing File

You are currently viewing VB.net Program to Append Text Into an Already Existing File

VB.Net program to append text into an already existing file

'VB.Net program to append text into an already existing file.

Imports System.IO

Module Module1
    Sub Main()
        Dim str As String = Nothing

        Try
            str = File.ReadAllText("sample.txt")

            Console.WriteLine("Content of file before append text: ")
            Console.WriteLine(str)

            Console.WriteLine("Enter text to append into file:")
            str = Console.ReadLine()

            File.AppendAllText("sample.txt", str)

            Console.WriteLine("Content after append:")
            str = File.ReadAllText("sample.txt")
            Console.WriteLine(str)


        Catch ex As FileNotFoundException
            Console.WriteLine("File does not exist")
        End Try
    End Sub
End Module
Content of file before append text:
Hello, how are you.
Enter text to append into file:
I am fine.
Content after append:
Hello, how are you.I am fine.
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply