C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Here: This program reads the data from a "file.txt" that is located in the same directory as the VB.NET executable.
And: It displays that data to the screen with Console.WriteLine. Each String can be used in any way.
File: file.txt
This is a text line.
This is a second line.
VB.NET program that uses File.ReadLines
Imports System.IO
Module Module1
Sub Main()
' Loop over lines in file.
For Each line As String In File.ReadLines("file.txt")
' Display the line.
Console.WriteLine("-- {0}", line)
Next
End Sub
End Module
Output
-- This is a text line.
-- This is a second line.
Tip: File.ReadAllLines stores the entire file contents in a String array. File.ReadLines does not.
Also: Some programs require a String array for further processing. In these cases, using ReadAllLines is better.
String Array