From the course: C# and .NET Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Reading and writing files

Reading and writing files - C# Tutorial

From the course: C# and .NET Essential Training

Reading and writing files

- In order for files to be useful, they have to contain some content. And for that to happen, we need to be able to read and write that content. So let's open the program code, for the Read Write Files example. And again, I'm going to be working on text content here to keep things simple. So for the first example, let's use the WriteAllText Function, to write content into a given file. So I will call the File.WriteAllText function, give that a file name and write, "This is a text file." So this function overwrites the existing content of a file. So be careful how you use it. And similarly, the ReadAlLText Function, reads the entire content of a text file into memories. Let's do that next. So I'll make a string to hold my content, and then we'll ReadAllText of that file name. And then we'll just print out that text. All right. So now we have code that creates a file and reads the file. So we were going to write the…

Contents