C#通过流写入一行数据到文件
这篇文章主要介绍了C#通过流写入一行数据到文件的方法,涉及C#针对文本文件读写的基本技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了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(); }
}
}
}