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:\\textwriter.txt"))
{
writer.writeline("hello c#, textwriter");
writer.writeline("c# file handling by h3.com");
}
console.writeline("data written successfully...");
}
}
}
执行上面示例代码后,打开textwriter.txt得到以下结果 -
hello c#, textwriter
c# file handling by h3.com