📅  最后修改于: 2020-10-31 04:12:15             🧑  作者: Mango
C#TextWriter类是一个抽象类。它用于将文本或一系列连续字符写入文件。在System.IO命名空间中找到它。
让我们看一下写两行数据的TextWriter类的简单示例。
using System;
using System.IO;
namespace TextWriterExample
{
class Program
{
static void Main(string[] args)
{
using (TextWriter writer = File.CreateText("e:\\f.txt"))
{
writer.WriteLine("Hello C#");
writer.WriteLine("C# File Handling by JavaTpoint");
}
Console.WriteLine("Data written successfully...");
}
}
}
输出:
Data written successfully...
f.txt:
Hello C#
C# File Handling by JavaTpoint