StreamWriter.WriteLine : StreamWriter « System.IO « C# / C Sharp by API






StreamWriter.WriteLine

  

using System;
using System.IO;

public class IOExample
{
  static void Main() {   
    FileStream fs;
    StreamWriter sw;


    try {
      fs = new FileStream("practice.txt", FileMode.Open );
      sw = new StreamWriter(fs);

      // write a line to the file
      string newLine = "Not so different from you and me";
      sw.WriteLine(newLine);

      // close the streams
      sw.Close();
      fs.Close();
    } catch (IOException ioe) {
      Console.WriteLine("IOException occurred: "+ioe.Message);
    }
  }
}

   
    
  








Related examples in the same category

1.new StreamWriter
2.StreamWriter.Flush
3.StreamWriter.Write