我得到"'初始化'没有这样的文件或目录错误"当我尝试运行以下代码时: (摘自'学习Ruby The Hard Way')
#Code start
filename=ARGV.first
txt=File.open(filename)
puts "Here is your file: #{filename}"
puts txt.read()
puts "Type it again"
file_again=STDIN.gets.chomp()
txt_again=File.open(file_again)
puts txt_again.read()
#Code end
ruby文件和txt文件都在同一个目录中,即使这样也会出错。
这是我在cmd中遇到的错误:
fileread.rb ex.txt
Here is your file: ex.txt
type it again
hello world
C:/Documents and Settings/Administrator/fileread.rb:8:in `initialize': No such f
ile or directory - hello world (Errno::ENOENT)
from C:/Documents and Settings/Administrator/fileread.rb:8:in `open'
from C:/Documents and Settings/Administrator/fileread.rb:8:in main
答案 0 :(得分:0)
当它要求你再次输入时,你应该输入ex.txt
。