title |
---|
Files |
readAll()
to read all the file into a single string variable. Fast but not practical for enormous files. UsesplitLines
iterator to do line-based manipulations
readLine()
to read from file a line at a time
CsvParse()
withreadRow()
to perform line-based manipulation for rows of text that need to be broken into "fields".
import parsecsv
memfiles
andlines()
iterator to iterate over memory mapped portions of the file (see example above).
The defer()
statement can be used instead of try:
finally:
blocks
import strutils
var
lineCnt = 0
f = open("test_readfile2.nim")
defer: close(f)
for line in f.readAll().splitLines():
inc lineCnt
echo lineCnt