Mega Code Archive

 
Categories / VB.Net / File Directory
 

File Create creates or overwrites a file in the specified path

Imports System Imports System.IO Imports System.Text Public Class Test     Public Shared Sub Main()         Dim path As String = "c:\temp\MyTest.txt"         Try             If File.Exists(path) Then                 File.Delete(path)             End If             Dim fs As FileStream = File.Create(path)             Dim info As Byte() = New UTF8Encoding(True).GetBytes("This is some text in the file.")             fs.Write(info, 0, info.Length)             fs.Close()             Dim sr As StreamReader = File.OpenText(path)             Do While sr.Peek() >= 0                 Console.WriteLine(sr.ReadLine())             Loop             sr.Close()         Catch ex As Exception             Console.WriteLine(ex)                End Try     End Sub End Class