Ruby 读写文件

写:

File.open('test.rb','w') do |f2|

  f2.puts "This is a test \n Good day"

end



读:

File.open('test.rb','r') do |f1|

    while line=f1.gets

        puts line

    end

end


注:r只读 r+读写  w只写,覆盖原文件或创建一个新文件





posted @ 2012-01-19 17:22  大鱼大鱼  阅读(188)  评论(0编辑  收藏  举报