Tutorial by Examples

To write the contents of a string to a file: Dim toWrite As String = "This will be written to the file." System.IO.File.WriteAllText("filename.txt", toWrite) WriteAllText will open the specified file, write the data, and then close the file. If the target file exists, it is ...
To read the contents to a file into a string variable: Dim fileContents As String = System.IO.File.ReadAllText("filename.txt") ReadAllText will open the specified file, read data to the end, then close the file. To read a file, separating it into an array element for each line: Dim f...
Using sw As New System.IO.StreamWriter("path\to\file.txt") sw.WriteLine("Hello world") End Using The use of a Using block is recommended good practice when using an object that Implements IDisposable

Page 1 of 1