private void button1_Click(object sender, EventArgs e) { try { FileStream fileStrm = File.Open("c:\\testfile.txt", FileMode.OpenOrCreate); StreamWriter writer = new StreamWriter(fileStrm); writer.WriteLine("First Line"); for (int i = 2; i < 100; i++) { writer.WriteLine("This is line {0}", i); } writer.Close(); fileStrm.Close(); Console.WriteLine("File created!"); } catch (IOException ex) { Console.WriteLine("Error in handling file!\n" + ex.Message.ToString() ); } }
Saturday, February 4, 2012
Writing Text to files( C#.net )
Labels:
C#.net,
FileStream,
StreamWriter,
TextFiles
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment