当前位置:主页 > 软件编程 > .NET代码 >

C#通过流写入一行数据到文件的方法

时间:2021-05-17 08:39:58 | 栏目:.NET代码 | 点击:

本文实例讲述了C#通过流写入一行数据到文件的方法。分享给大家供大家参考。具体如下:

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(); }
  }
 }
}

希望本文所述对大家的C#程序设计有所帮助。

您可能感兴趣的文章:

相关文章