Invalid argument

I’m trying to run the following program:

class XYZ
puts “Enter the file name you esnt to work with”
file_name = gets
input_file = File.open(file_name,‘r’)
output_file = File.open(‘output.txt’,‘w’)
for i in 1…1000
puts input_file.readline
end
end

But, get the following error:

xyz.rb:4:in initialize': Invalid argument - abc.txt (Errno::EINVAL) from xyz.rb:4:inopen’
from xyz.rb:4:in <class:XYZ>' from xyz.rb:1:in

Why is that? How can I solve this issue?>

Thanks.

I think it is because you are passing “abc.txt\n” to File.open().
Try:
File.open(file_name.chomp, ‘r’) do |f|
1.upto(1000) do |i|
puts f.readline
end
end

Rpag … wrote in post #1167053:

I think it is because you are passing “abc.txt\n” to File.open().
Try:
File.open(file_name.chomp, ‘r’) do |f|
1.upto(1000) do |i|
puts f.readline
end
end

Thanks for your reply. Yes, I needed the “chomp” part for it to work.