写:
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只写,覆盖原文件或创建一个新文件
写:
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只写,覆盖原文件或创建一个新文件
转载于:https://www.cnblogs.com/landebug/archive/2012/01/19/2416684.html