### Read Textfile Line by Line

Reads a textfile line by line and outputs to B4J Log.
`Sub readTextFileByLine(sFolder, sFile As String)
Dim tr As TextReader
tr.Initialize(File.OpenInput(sFolder, sFile))
Dim line As String
line = tr.ReadLine
Do While line <> Null
Log(line)
line = tr.ReadLine
Loop
tr.Close
End Sub`
By the way:
This can also be accomplished by using JavaObjects. Example shows usage of constructors and methods.
' Reference: http://docs.oracle.com/javase/8/docs/api/java/io/FileReader.html
' Reference: http://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html
`Sub readTextFileByLineJO(sFolder, sFile As String)
Dim joFr, joBr As JavaObject
' Create new constructor FileReader String FileName
joFr.InitializeNewInstance("java.io.FileReader", Array(sFolder & sFile))
' Create new Constructor buffering character-input stream that uses a default-sized input buffer.
joBr.InitializeNewInstance("java.io.BufferedReader",Array(joFr))
' Reads a line of text.
' A line = terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed by a linefeed.
Dim s As String = joBr.RunMethod("readLine",Null)
Do While s <> "null" ' will be "null" at end of file
Log(s)
s = joBr.RunMethod("readLine",Null)
Loop
joBr.RunMethod("close",Null)
End Sub`

Changed: , Category: TextReader and TextWriter, File: T6C263M1952.htm, ID: 1952