常规处理:

File.open("sampel.txt") do |file|
  file.each_line do |line|
    print line
  end
end

 上式与下式等价

file = File.open("sample.txt")
begin
  file.each_line do |line|
      print line 
  end
ensure
  file.close  
end

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-06
  • 2022-12-23
  • 2021-12-13
  • 2021-07-09
  • 2021-08-18
猜你喜欢
  • 2021-09-06
  • 2021-10-26
  • 2021-08-14
相关资源
相似解决方案