Bird
0
0

How can you append text to an existing file "append.txt" using File.write?

hard📝 Application Q9 of 15
Ruby - File IO
How can you append text to an existing file "append.txt" using File.write?
AFile.write("append.txt", "More text")
BFile.write("append.txt", "More text", append: true)
CFile.write("append.txt", "More text", mode: "w+")
DFile.write("append.txt", "More text", mode: "a")
Step-by-Step Solution
Solution:
  1. Step 1: Recall File.write options for mode

    To append, use mode: "a" to open file in append mode.
  2. Step 2: Identify correct option

    File.write("append.txt", "More text", mode: "a") correctly uses mode: "a" to append text.
  3. Final Answer:

    File.write("append.txt", "More text", mode: "a") -> Option D
  4. Quick Check:

    Use mode: "a" to append with File.write [OK]
Quick Trick: Use mode: "a" to append text with File.write [OK]
Common Mistakes:
  • Using default mode which overwrites
  • Using invalid option append: true
  • Using mode "w+" which overwrites or truncates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes