C Write a row of data to a file through a stream

  • 2021-07-06 11:37:03
  • OfStack

This article illustrates how C # writes 1 row of data to a file through a stream. Share it for your reference. The details are as follows:


using System;
using System.IO;
public class WriteFileStuff {
 public static void Main() {
  FileStream fs = new FileStream("c:\\tmp\\WriteFileStuff.txt", FileMode.OpenOrCreate, FileAccess.Write);      
  StreamWriter sw = new StreamWriter(fs);
  try {
    sw.WriteLine("Howdy World.");
  } finally {
    if(sw != null) { sw.Close(); }
  }
 }
}

I hope this article is helpful to everyone's C # programming.


Related articles: