Concept Flow - Writing text files
Start
Open/Create File
Write Text to File
Close File
End
The program opens or creates a file, writes text into it, then closes the file to save changes.
using System.IO; File.WriteAllText("example.txt", "Hello, world!");
| Step | Action | File State | Output/Result |
|---|---|---|---|
| 1 | Call File.WriteAllText with filename and text | File 'example.txt' opened or created | No output |
| 2 | Write "Hello, world!" to file | File contains "Hello, world!" | No output |
| 3 | Close file to save changes | File closed and saved | No output |
| 4 | End of operation | File 'example.txt' now has text | No output |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|---|
| filename | "example.txt" | "example.txt" | "example.txt" | "example.txt" | "example.txt" |
| text | "Hello, world!" | "Hello, world!" | "Hello, world!" | "Hello, world!" | "Hello, world!" |
| file state | none | opened/created | written | closed | closed |
Writing text files in C#: Use File.WriteAllText(filename, text) to create or overwrite a file. The file is opened, text is written, then file is closed automatically. No console output is produced. Always specify the filename and the text to write.