»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books
»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects
»Competition
Community
Winners
Prizes
Write For Us
Members
»Other Resources
Links
Dotnet Resources
|
Writing to a text file in c#The .NET Framework includes convenience classes that make reading and writing text files very easy this small article shows you how to create and write to a text file
The code when executed creates a text file called tx.txt in the current working directory.
The WriteLine method allows us to write to the text file
Once we write the text we have to close the file using the tw.close method
using System.IO;
static void Main()
{
// create the writer and open the file
TextWriter tw = new StreamWriter("t.txt");
// write a line of text to the file
tw.WriteLine("Hello world!");
// close the stream
tw.Close();
}
|
|