#建立一个222.rb文件并且输入字符
file = File.open(222.rb,w+)
file.puts 123\nwadwa\n12124124\ndwdw
file.close
#输出222.rb的内容
File.open(222.rb,r+) do |file|
while line = file.gets
puts line
end
end
#直接用IO操作文件
IO.foreach(222.rb) do |line|
puts line if line =~/abc/ #输出