VB.Net program to copy the content of one file to another file

Here, we are going to learn how to copy the content of one file to another file in VB.Net?
Submitted by Nidhi, on January 10, 2021

Here, we will copy the content of one file to another file using the Copy() method of File class.

Program/Source Code:

The source code to copy the content of one file to another file is given below. The given program is compiled and executed successfully.

'VB.Net program to copy the content of one file to another file.

Imports System.IO

Module Module1
    Sub Main()
        Try
            Dim data As String

            data = File.ReadAllText("xyz.txt")
            Console.WriteLine("Content of xyz.txt :" & vbCrLf & data)

            File.Copy("xyz.txt", "abc.txt")

            data = File.ReadAllText("abc.txt")
            Console.WriteLine("Content of abc.txt : " & vbCrLf & data)

        Catch ex As FileNotFoundException
            Console.WriteLine("File does not exist")
        End Try
    End Sub
End Module

Output:

Content of xyz.txt :
Hello, How are you?
Content of abc.txt :
Hello, How are you?
Press any key to continue . . .

Explanation:

In the above program, we created the module Module1 that contains the Main() function. The Main() function is the entry point for the program. Here, we will create a new and copy the content of the existing file into the newly created file using the Copy() function of the File class. Here, we copied the content of the "xyz.txt" file into the "abc.txt" file.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.