用C#写一个把内容输出到txt文本的帮助类
以下是一个用C#编写的将内容输出到txt文本的帮助类:
using System.IO;
public static class TxtHelper
{
public static void WriteToFile(string filePath, string content)
{
using (StreamWriter writer = new StreamWriter(filePath))
{
writer.Write(content);
}
}
}
使用示例:
string filePath = "C:\\output.txt";
string content = "Hello, world!";
TxtHelper.WriteToFile(filePath, content);
这将在C盘根目录下创建一个名为“output.txt”的文件,并将“Hello, world!”写入其中。
原文地址: https://www.cveoy.top/t/topic/eHj2 著作权归作者所有。请勿转载和采集!