Bird
Raised Fist0

How can you append text to an existing file "log.txt" using StreamWriter without overwriting it?

hard🚀 Application Q9 of Q15
C Sharp (C#) - File IO
How can you append text to an existing file "log.txt" using StreamWriter without overwriting it?
Anew StreamWriter("log.txt", append: false)
BStreamWriter.AppendText("log.txt")
Cnew StreamWriter.Append("log.txt")
Dnew StreamWriter("log.txt", append: true)
Step-by-Step Solution
Solution:
  1. Step 1: Recall StreamWriter constructor parameters

    StreamWriter has a constructor with a boolean to specify append mode.
  2. Step 2: Identify correct append usage

    Passing append: true opens file to add text without erasing existing content.
  3. Final Answer:

    new StreamWriter("log.txt", append: true) -> Option D
  4. Quick Check:

    Append mode = true to add text [OK]
Quick Trick: Use append: true to add text without overwrite [OK]
Common Mistakes:
MISTAKES
  • Using append: false which overwrites
  • Assuming Append() method exists
  • Confusing AppendText() static method with constructor

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes