Write Data to file in .Net ( VB and C# )



This tutorial will go over how to write data to a text file in VB.Net and C#.Net

.Net uses StreamWriter Class To write data to file. StreamWriter is designed for character output in a particular encoding, whereas classes derived from Stream are designed for byte input and output.

VB .Net

Dim objWriter As New System.IO.StreamWriter("d:\abc.txt", True)  
objWriter.WriteLine("Some Text here")
objWriter.Close()

C# .Net

using (System.IO.StreamWriter objWriter = new System.IO.StreamWriter(@"abc.txt", true))
{
       objWriter.WriteLine("Some Text here");
}
objWriter.Close(); 
 

0 comments :