Help Me with this Code!

I am new to ruby and I am trying to learn it on my own. I downloaded the
code below from http://sandbox.mc.edu and I’m trying to disect it and
under stand how it works, but as it is right now it gives me an error on
line 10 and 4. i created a txt file and put it on my desktop to test the
code but like i said before its giving me the 2 error codes on line 10
and 4. Can someone help me understand how this code works? I’ve attached
the ruby file, which i also named test.

Count and report the number of lines and characters in a file.

print "File name: "
fn = gets.chomp
begin
f = open(fn)
nlines = 0
length = 0
f.each { |line| nlines += 1; length += line.length }
rescue
print "File read failed: " + $! + “\n”
else
print fn, ": ", nlines, " lines, “, length, " characters.\n”
end