Jim, Sales Andy, Sales Kelly, Customer Service Creed, Quality Assurance Michaes, Manager
stack overflow Questions Ruby IO
mode meaning
r read-only w write-only, truncates existing file to zero length or creates a new file for writing a write-only, starts at end of file if file exists, otherwise creates a new file for reading and writing
File.open("employees.txt", "a") do |file| file.write("\nOscar, Accounting") end
Jim, Sales Andy, Sales Kelly, Customer Service Creed, Quality Assurance Michaes, Manager Oscar, Accounting
File.open("employees.txt", "w") do |file| file.write("\nOscar, Accounting") end
Oscar, Accounting
File.open("index.html", "w") do |file| file.write("
Hello World is created in index.html.
from stackoverflow r+ Read-write, starts at beginning of file.
File.open("index.html", "r+") do |file| file.readline() file.write("Hi") end
Jim, Sales Hidy, Sales Kelly, Customer Service Creed, Quality Assurance Michaes, Manager Oscar, Accounting
File.open("index.html", "r+") do |file| file.readchar() file.write("Hi") end
Recommended Posts