mark

mark

  • NA
  • 26
  • 0

creating / writing / reading text files

Aug 10 2007 9:25 PM

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)