new StreamWriter(String filePath) : StreamReader « System.IO « C# / C Sharp by API






new StreamWriter(String filePath)

 
using System;
using System.IO;


public class MyStreamWriterReader {
    static void Main(string[] args) {
        StreamWriter writer = new StreamWriter("reminders.txt");
        writer.WriteLine("...");
        writer.WriteLine("Don't forget these numbers:");
        for (int i = 0; i < 10; i++)
            writer.Write(i + " ");

        writer.Write(writer.NewLine);

        writer.Close();
        StreamReader sr = new StreamReader("reminders.txt");
        string input = null;
        while ((input = sr.ReadLine()) != null) {
            Console.WriteLine(input);
        }
    }
}

   
  








Related examples in the same category

1.new StreamReader(FileStream fs)
2.new StreamWriter(fs, Encoding.UTF8)
3.StreamReader.Peek()
4.StreamReader.ReadLine()
5.StreamReader.ReadToEnd()