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

前端 未结 6 1635
北海茫月
北海茫月 2020-12-04 18:03

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 l         


        
6条回答
  •  既然无缘
    2020-12-04 18:30

    Ditto Casper's answer:

    puts Dir.pwd
    

    As soon as you know current working directory, specify the file path relatively to that directory.

    For example, if your working directory is project root, you can open a file under it directly like this

    json_file = File.read(myfile.json)
    

提交回复
热议问题