I have been reading books trying to learn .net on my own. I am working on an exercise that asks me to create a 1MB file. what i have below does work, but it seems to me there would be a more efficeient way. It seems like what i am doing would cause a lot of overhead. Any advice for making a 1MB file easier than what i have? =)
Module Module1
Sub Main()
Dim fileName As String = "myfile.txt"
Dim fileInfo As New FileInfo(fileName)
Dim length As Integer = 0
Dim MB As Integer = 1048576
Do
If File.Exists(fileName) Then
Dim stream As StreamWriter = File.AppendText(fileName)
length = fileInfo.Length()
stream.WriteLine("HELLO WORLD sfldkjsdlfjsdklfjklsjfklsd")
stream.Flush()
stream.Close()
Else
Dim stream As StreamWriter = File.CreateText(fileName)
stream.WriteLine("HELLO WORLD HELLO WORLD!!!!")
stream.Flush()
stream.Close()
End If
length += fileInfo.Length
Loop Until length >= MB
End Sub
End Module