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 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
f = open(fn)
nlines = 0
length = 0
f.each { |line| nlines += 1; length += line.length }
print "File read failed: " + $! + “\n”
print fn, ": ", nlines, " lines, “, length, " characters.\n”