C Write Data to File via Stream

  • 2021-07-09 09:06:13
  • OfStack

This article illustrates how C # writes data to a file through a stream. Share it for your reference. The specific implementation method is 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: