9
Answers

creating / writing / reading text files

mark

mark

17y
2.8k
1

So I have tried looking up many tutorials and examples for creating, writing, and readin text files. I dont understand how to create a text file outside of my c# program folder because I always get errors. I want to create a text file to my desktop, write "I wrote in your file!" in it, and then read it and display it in a console window. Can I see some help or examples? Thanks!

 

static void Main(string[] args)

{

FileStream file = new FileStream("C://Desktop/guess.txt", FileMode.CreateNew , FileAccess.Write);

// write a line of text to the file

StreamWriter sw = new StreamWriter(file);

sw.Write("Hello file system world!");

sw.Close();

}

Answers (9)