Read all the lines of the file

var lines = "/etc/passwd".to_path.read_lines

print "{lines.length} users"

for l in lines do
    var fields = l.split(":")
    print "name={fields[0]} uid={fields[2]}"
end

last_error is updated to contains the error information on error, and null on success. In case of error, the result might be empty or truncated.

See Reader::read_lines for details.

Property definitions

core $ Path :: read_lines
	# Read all the lines of the file
	#
	# ~~~
	# var lines = "/etc/passwd".to_path.read_lines
	#
	# print "{lines.length} users"
	#
	# for l in lines do
	#     var fields = l.split(":")
	#     print "name={fields[0]} uid={fields[2]}"
	# end
	# ~~~
	#
	# `last_error` is updated to contains the error information on error, and null on success.
	# In case of error, the result might be empty or truncated.
	#
	# See `Reader::read_lines` for details.
	fun read_lines: Array[String]
	do
		var s = open_ro
		var res = s.read_lines
		s.close
		last_error = s.last_error
		return res
	end
lib/core/file.nit:594,2--618,4