Dim reader As New IO.StreamReader("C:\Test\Text1.txt") Dim line As String line = reader.ReadLine '1行目 line = reader.ReadLine '2行目 line = reader.ReadLine '3行目 reader.Close() MsgBox("3行目は" & vbNewLine & line & vbNewLine & "でした。")
Dim reader As New IO.StreamReader("C:\Test\Text1.txt") Dim line As String = "" For lineNumer As Integer = 1 To 3 line = reader.ReadLine Next reader.Close() MsgBox("3行目は" & vbNewLine & line & vbNewLine & "でした。")
Private Function ReadFileLine(ByVal fileName As String, ByVal lineNumber As Integer) As String Dim reader As New IO.StreamReader(fileName) Dim line As String = "" For lineNumer As Integer = 1 To lineNumber line = reader.ReadLine Next reader.Close() Return line End Function
Dim line As String = ReadFileLine("C:\Test\Text1.txt", 3) MsgBox("3行目は" & vbNewLine & line & vbNewLine & "でした。")
Dim line As String = IO.File.ReadAllLines("C:\Test\Text1.txt")(2) MsgBox("3行目は" & vbNewLine & line & vbNewLine & "でした。")