Tuesday, August 19, 2008

HOW TO CREATE AND WRITE A FILE IN VB.NET

Dim FILE_NAME As String = "C:\file2.txt"

If System.IO.File.Exists(FILE_NAME) = True Then

Dim fs As New FileStream(FILE_NAME, FileMode.Create, FileAccess.Write)
Dim s As New StreamWriter(fs)
s.WriteLine("Congrates you have created a new file")
s.Close()

ElseIf System.IO.File.Exists(FILE_NAME) = False Then

Dim fs As New System.IO.FileStream(FILE_NAME, FileMode.Create, FileAccess.Write)
Dim s As New System.IO.StreamWriter(fs)
s.WriteLine("Congrates you have created a new file")
s.Close()

End If

No comments: