create text file

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?
 
B

Ben Dewey

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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top