C#StreamWriter类
C#StreamWriter类用于以特定编码将字符写入流。它继承了TextWriter类。它提供重载的write()和writeln()方法将数据写入文件。
C#StreamWriter示例
using System; using System.IO; public class StreamWriterExample { public static void Main(string[] args) { FileStream f = new FileStream("e:\\output.txt", FileMode.Create); StreamWriter s = new StreamWriter(f); s.WriteLine("hello c#"); s.Close(); f.Close(); Console.WriteLine("File created successfully..."); } }
输出:
File created successfully...
现在打开文件,你会在 output.txt 文件中看到文本“hello c#”。
hello c#
祝学习愉快! (发现内容有误?请选中要编辑的内容 -> 右键 -> 修改 -> 提交!帮助我们改进教程质量)
精选教程推荐
👇 以下精选教程可能对您有帮助,拓展您的技术视野
暂无学习笔记,成为第一个分享的人吧!
您的笔记将帮助成千上万的学习者