Ruby's File.open gives "No such file or directory - text.txt (Errno::ENOENT)" error

Viewed 106347

I installed Ruby 1.9.2 on my Win 7 machine. Created a simple analyzer.rb file. It has this one line:

File.open("text.txt").each {|line| puts line}

When I run the code, it gives me this error:

analyzer.rb:1:in `initialize': No such file or directory - text.txt (Errno::ENOENT)
from analyzer.rb:1:in `open'
from analyzer.rb:1:in `<main>'
Exit code: 1

I don't get it. There is a text.txt file in the same directory as the analyzer.rb file. I also tried feeding the absolute path of the file, C:\Ruby192\text.txt, but no dice. What am I missing?

6 Answers
Related