When using files in Ruby, what is the difference between the r+
and w+
modes? What about the a+
mode?
Access modes r+
, w+
and a+
opens the file in read and write mode, but with the following difference:
r+
starts at beginning of file, but will not create a new file if it doesn't exists.
w+
truncates existing file to zero length if the file exists, otherwise creates a new file.
a+
starts at end of file if file exists, otherwise creates a new file.