Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (34 sloc) 733 Bytes
// A few examples of reading a file.
import io
// 1. The primitive way.
do
val file = open("example/File.mag")
while true do
val line = file readLine()
if line == nothing then break
print(line)
end
file close()
end
// 2. Using "use" instead of explicit close().
do
open("example/File.mag") use with
while true do
val line = it readLine()
if line == nothing then break
print(line)
end
end
end
// 3. Using the file as an iterator.
do
open("example/File.mag") use with
for line in it do print(line)
end
end
// 4. Reading it all at once.
do
open("example/File.mag") use with
print(it read())
end
end
Something went wrong with that request. Please try again.