Read a file one line at a time,
as opposed to reading the entire file at once.



Related tasks

 Read a file character by character
 Input loop.


[indent=4]
/*
   Read file line by line, in Genie
 
   valac readFileLines.gs
   ./readFileLines [filename]
*/
 
init
 
    fileName:string
    fileName = (args[1] is null) ? "readFileLines.gs" : args[1]
    var file = FileStream.open(fileName, "r")
    if file is null
        stdout.printf("Error: %s did not open\n", fileName)
        return
 
    lines:int = 0
    line:string? = file.read_line()
    while line is not null
        lines++
        stdout.printf("%04d %s\n", lines, line)
        line = file.read_line()