Files, Directories and I/O

# Reading
my $content = 'data.txt'.IO.slurp;                 # whole file
my @lines   = 'data.txt'.IO.lines;                 # lazy lines (chomped)
for 'data.txt'.IO.lines -> $line { say $line.uc }
my $words = 'data.txt'.IO.words.elems;

# Writing
'out.txt'.IO.spurt("Hello\n");                     # overwrite
'out.txt'.IO.spurt("More\n", :append);
spurt 'out2.txt', "functional style\n";

# File handles
my $fh = open 'log.txt', :w;                       # :r (default), :w, :a (append), :rw, :x (exclusive create)
$fh.say('first line');
$fh.print('no newline');
$fh.close;
given open('log.txt') -> $in {                     # read with a handle
    while my $l = $in.get { say $l }
    $in.close;
}
my $in2 = open 'log.txt';
LEAVE $in2.close;                                  # ensure closing with a phaser

# Binary
my $bin = 'image.png'.IO.open(:bin);
my Buf $header = $bin.read(8);
$bin.close;
say $header.list.fmt('%02x', ' ');

# Paths
my $path = 'docs/report.txt'.IO;
say $path.basename, ' ', $path.extension, ' ', $path.parent, ' ', $path.absolute;
say $path.e, ' ', $path.f, ' ', $path.d, ' ', $path.r, ' ', $path.w;   # exists, file, dir, readable, writable
say $path.s if $path.e;       
…