Files in Visual Basic
Write, append, stream and delete through System.IO.
Imports System.IO
Dim target = Path.Combine(Path.GetTempPath(), "typestar_notes.txt")
File.WriteAllLines(target, {"first line", "second line"})
File.AppendAllText(target, "third line" & Environment.NewLine)
For Each line In File.ReadLines(target)
Console.WriteLine($"> {line}")
Next
Console.WriteLine($"bytes on disk: {New FileInfo(target).Length}")
File.Delete(target)
Console.WriteLine($"still there: {File.Exists(target)}")
How it works
Path.Combinebuilds the temp-file path portably.WriteAllLinescreates;AppendAllTextextends without clobbering.File.ReadLinesstreams lazily — no whole-file array needed.FileInforeports size;DeleteandExistsclose the loop.
Keywords and builtins used here
DimEachForImportsNext
The run, in numbers
- Lines
- 13
- Characters to type
- 429
- Tokens
- 95
- Three-star pace
- 85 tpm
At the three-star pace of 85 tokens a minute, this run takes about 67 seconds.
Step 1 of 3 in Files & errors, step 25 of 29 in Language basics.