Files

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have s string variable.
And I want to save it into a txt file..
How Can I do it?
 
Hi,

Use StreamWriter & WriteLine method

Cheers,
 
Hi,

If you have string variables and want to create a text file StreamWriter is
better, it does provide WriteLine( string ) weather FileStream only can
write Byte as it's a byte oriented stream.

Cheers,
 
I don't kno why but it doesn't work, the file is created but the string isn't
being written to it.
the code is:
StreamWriter f= new StreamWriter("file.txt");
public Form1()
{ InitializeComponent();
f.WriteLine("blablabla");

}
The file: file.txt is empty
 
Hi,

Try:
public Form1()
{ InitializeComponent();
StreamWriter f= new StreamWriter("file.txt");
f.WriteLine("blablabla");
f.Close();


}

cheers,
 

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

Back
Top