C#操作文本文件之添加文本操作是如何实现的呢?让我们来看看具体的实例方式:
- using System;
- using System.IO;
- class Test
- //C#操作文本文件之添加文本操作
- {
- public static void Main()
- {
- // Create an instance of StreamWriter to write text to a file.
- // The using statement also closes the StreamWriter.
- using (StreamWriter sw = new StreamWriter("TestFile.txt"))
- {
- // Add some text to the file.
- sw.Write("This is the ");
- sw.WriteLine("header for the file.");
- sw.WriteLine("-------------------");
- // Arbitrary objects can also be written to the file.
- sw.Write("The date is: ");
- sw.WriteLine(DateTime.Now);
- }
- //C#操作文本文件之添加文本操作
- }
- }
C#操作文本文件之添加文本操作的基本情况就向你介绍到这里,希望对你了解和学习C#操作文本文件有所帮助。
【编辑推荐】