From: Stefano Crocco Date: 2008-06-05T02:26:38+09:00 Subject: Re: Beginner: Read file On Wednesday 04 June 2008, Justin To wrote: > report = File.open('ReportTxt.txt', 'r') do |L| >    while line = L.gets > >   report.getc.chr > >     end > end There are at least two problems with your code: 1) you use the variable report in the block, but the variable is assigned a value *after* the File.open method returns. This means that when you call report.getc inside your block, report is nil, hence the error you're getting (by the way, when you ask for help, you should specify what kind of error you're getting). 2) You use L.gets to iterate. But: a) gets, with no argument, iterates linewise, which means you'll read a character for each line; b) gets moves the position in the file, which means that, after L.gets reads the last line of the file, you'll get an error. To achieve what you want, you can use the following code (by the way, capital letters in ruby are used for constants, so it's better not to use them for block variables): File.open('ReportTxt.txt', 'r') do |f| until f.eof? f.getc.chr end end I hope this helps Stefano