C#操作文本文件之添加文本操作浅析

C#操作文本文件之添加文本操作是如何实现的呢?让我们来看看具体的实例方式:

 
 
 
  1. using System;  
  2.  
  3. using System.IO;  
  4.  
  5. class Test   
  6.  
  7.  //C#操作文本文件之添加文本操作
  8. {  
  9.  
  10. public static void Main()   
  11.  
  12. {  
  13.  
  14. // Create an instance of StreamWriter to write text to a file.  
  15.  
  16. // The using statement also closes the StreamWriter.  
  17.  
  18. using (StreamWriter sw = new StreamWriter("TestFile.txt"))   
  19.  
  20. {  
  21.  
  22. // Add some text to the file.  
  23.  
  24. sw.Write("This is the ");  
  25.  
  26. sw.WriteLine("header for the file.");  
  27.  
  28. sw.WriteLine("-------------------");  
  29.  
  30. // Arbitrary objects can also be written to the file.  
  31.  
  32. sw.Write("The date is: ");  
  33.  
  34. sw.WriteLine(DateTime.Now);  
  35.  
  36. }  
  37.  //C#操作文本文件之添加文本操作
  38. }  
  39.  

C#操作文本文件之添加文本操作的基本情况就向你介绍到这里,希望对你了解和学习C#操作文本文件有所帮助。

【编辑推荐】

  1. C# 操作符之is应用浅析
  2. C# 操作符之三元操作符浅析
  3. C# 操作符之 . 运算符应用详解
  4. C# 操作符分类及应用浅析
  5. C#操作文本文件实例浅析
THE END