VB.Net program to delete a specified file

Here, we are going to learn how to delete a specified file in VB.Net?
Submitted by Nidhi, on January 08, 2021

Here, we will use the Delete() method of the File class to delete the file from the system.

Program/Source Code:

The source code to delete a specified file is given below. The given program is compiled and executed successfully.

'VB.Net program to delete a specified file.

Imports System.IO

Module Module1
    Sub Main()
        Try
            File.Delete("demo.txt")

            Console.WriteLine("File deleted successfully")

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

Output:

File deleted successfully
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 deleted the "demo.txt" file using Delete() method of the File class.

If the specified file does not exist in the computer system then a file not found exception gets generated and prints the appropriate message on the console screen.

VB.Net File Handling Programs »





Comments and Discussions




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.