C#使用System.IO.File类写入文件
示例
您可以使用System.IO.File.WriteAllText函数将字符串写入文件。
string text = "String that will be stored in the file"; System.IO.File.WriteAllText(@"C:\MyFolder\OutputFile.txt", text);
您还可以使用System.IO.File.WriteAllLines函数,该函数接收IEnumerable<String>第二个参数(与上一个示例中的单个字符串相反)。这使您可以从一行行中写入内容。
string[] lines = { "My first string", "My second string", "and even a third string" };
System.IO.File.WriteAllLines(@"C:\MyFolder\OutputFile.txt", lines);
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西