C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C# StreamWriterC# StreamWriter class is used to write characters to a stream in specific encoding. It inherits TextWriter class. It provides overloaded write() and writeln() methods to write data into file. C# StreamWriter exampleLet's see a simple example of StreamWriter class which writes a single line of data into the file. using System; using System.IO; public class StreamWriterExample { public static void Main(string[] args) { FileStream f = new FileStream("e:\\output.txt", FileMode.Create); StreamWriter s = new StreamWriter(f); s.WriteLine("hello c#"); s.Close(); f.Close(); Console.WriteLine("File created successfully..."); } } Output: File created successfully... Now open the file, you will see the text "hello c#" in output.txt file. output.txt: hello c#
Next TopicC# StreamReader
|