Complete the code to open a file for reading.
file = File.open('example.txt', '[1]')
Use mode 'r' to open a file for reading only.
Complete the code to open a file for writing (overwriting existing content).
file = File.open('output.txt', '[1]')
Use mode 'w' to open a file for writing and overwrite existing content.
Fix the error in the code to open a file for appending text.
file = File.open('log.txt', '[1]')
Use mode 'a' to open a file for appending text at the end.
Fill both blanks to open a file for reading and writing without erasing content.
file = File.open('data.txt', '[1]') file.write('Hello') if file.[2]
readable? does not confirm writing permission.Mode 'r+' opens for reading and writing without erasing. Use writable? to check if writing is allowed.
Fill all three blanks to open a file for appending, write a line, and close the file.
file = File.open('notes.txt', '[1]') file.[2]('New note\n') file.[3]
Use mode 'a' to append, write to add text, and close to save and close the file.
