How to write to file in Ruby?
I need to read the data out of database and then save it in a text file.
How can I do that in Ruby? Is there any file management system in Ruby?
Ruby File类将为您提供::new
和::open
来龙去脉,但它的父类IO类深入到#read
和#write
。
你在寻找以下吗?
File.open(yourfile, 'w') { |file| file.write("your text") }
You can use the short version:
File.write('/path/to/file', 'Some glorious content')
It returns the length written; see ::write for more details and options.
链接地址: http://www.djcxy.com/p/4362.html上一篇: Ruby中的行注释?
下一篇: 如何在Ruby中写入文件?