create text file

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I'm trying to create a text file and when i compile my code i keep getting
invalid token

FileInfo t = new FileInfo("test.txt");
StreamWriter Tex =t.CreateText();
Tex.WriteLine("test file");
Tex.Write(Tex.NewLine);
Tex.close();

the error i'm getting is
Invalid Token '(' in class , struct, or interface member declaration.

what am I missing or doing wrong?
 
To create a text file, replace the first two lines with


StreamWriter Tex = File.CreateText("test.txt");

This uses the Static System.IO.File.CreateText method to create the file.

And if you want to write a blank line just use Tex.WriteLine(); with no
parameters

this will create a blank line, there is no need to use Tex.NewLine;
 
Back
Top