View Category

Read the contents of a file into a string

fantom
contents := File(`file.text`).readAllStr

Process a file one line at a time

Open the source file to your solution and print each line in the file, prefixed by the line number, like:
1> First line of file
2> Second line of file
3> Third line of file
fantom
File(`input.text`).readAllLines.each |Str s, Int i| { echo("${i+1}> $s") }

Write a string to a file

fantom
File(`out.txt`).out.writeChars("some text").flush

Append to a file

fantom
File(`out.txt`).out(true).writeChars("some text").flush

Process each file in a directory

fantom
File(`./`).list.each { process(it) }

Process each file in a directory recursively

fantom
File(`./`).walk { process(it) }