There's a lot of ways to do file I/O. What you pieced together is good fundamentals, but here's a couple of other ways to accomplish it.
I hesitate to say this is "better" code, but it's a little more intent-revealing:
Code:
Using writer = File.AppendText("test.txt")
writer.WriteLine("123")
writer.WriteLine("456")
writer.WriteLine("789")
End Using
The Using statement guarantees the file is safely closed even if an error happens. The
File.AppendText() method goes to the trouble of opening all of the streams. You can see the
File methods here; lots of them are convenient.
Here's an alternate way to do it without worrying about opening and closing the file yourself:
Code:
Dim lines = {"123", "456", "789"}
File.AppendAllLines("test.txt", lines)
AppendAllLines() takes an enumeration of strings and appends each as a new line to a file.