VB.Net program to write data into a text file

Here, we are going to learn how to write data into a text file in VB.Net?
Submitted by Nidhi, on January 08, 2021

Here, we will read text data from the user and write it into a text file using the WriteAllText() method of the File class.

Program/Source Code:

The source code to write data into a text file is given below. The given program is compiled and executed successfully.

'VB.Net program to write text into a file.

Imports System.IO

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

        Console.WriteLine("Enter data to Write into File : ")
        str = Console.ReadLine()

        File.WriteAllText("sample.txt", str)
        Console.WriteLine("File Creation Done")
    End Sub
End Module

Output:

Enter data to Write into File :
Hello, how are you.
File Creation Done
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program. And, we created a local variable str of string type. After that read the value of the str variable from the user and then write data into the "sample.txt" file using WriteAllText() method of the File class.






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.