我是Ruby的新手程序员。请问有人可以给出在Ruby中使用r+、w+、a+模式打开文件的例子吗?它们与r、w、a模式有什么区别?
请解释并提供示例。
请解释并提供示例。
http://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html
r or rb
Open file for reading.
w or wb
Truncate to zero length or create file for writing.
a or ab
Append; open or create file for writing at end-of-file.
r+ or rb+ or r+b
Open file for update (reading and writing).
w+ or wb+ or w+b
Truncate to zero length or create file for update.
a+ or ab+ or a+b
Append; open or create file for update, writing at end-of-file.
echo "foobar" > some_file && ruby -e 'File.open("some_file", "a") { |f| f.puts "catdog" }'
- mbigras