Public Class Form1 Dim stream As IO.Stream Dim writer As IO.StreamWriter Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim fileName As String = "C:\vb\myfile.txt" stream = IO.File.Open(fileName, IO.FileMode.Create, IO.FileAccess.ReadWrite, IO.FileShare.None) writer = New IO.StreamWriter(stream) End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click writer.WriteLine(Now.ToString) End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click writer.Close() writer.Dispose() stream.Close() stream.Dispose() End Sub End Class