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.


/* NetRexx */
options replace format comments java crossref symbols nobinary
 
parse arg inFileName .
 
if inFileName = '' | inFileName = '.' then inFileName = './data/dwarfs.json'
lines = scanFile(inFileName)
loop l_ = 1 to lines[0]
  say l_.right(4)':' lines[l_]
  end l_
 
return
 
-- Read a file and return contents as a Rexx indexed string
method scanFile(inFileName) public static returns Rexx
 
  fileLines = ''
  do
    inFile = File(inFileName)
    inFileScanner = Scanner(inFile)
    loop l_ = 1 while inFileScanner.hasNext()
      fileLines[0] = l_
      fileLines[l_] = inFileScanner.nextLine()
      end l_
    inFileScanner.close()
 
  catch ex = FileNotFoundException
    ex.printStackTrace
  end
 
  return fileLines
 