Back to course

Working with Files: Write and Read

C# Zero to Hero: Comprehensive Programming Masterclass

File I/O Basics

C# provides the System.IO namespace to work with the computer's file system.

Write to File

csharp string text = "Hello File!"; File.WriteAllText("test.txt", text);

Read from File

csharp string content = File.ReadAllText("test.txt"); Console.WriteLine(content);

Always ensure the path is correct and your application has permissions.