C#寫文件操作實例淺析
作者:tina_yebo
C#寫文件的具體實現操作是什么呢?C#寫文件使用到的是什么方法呢?C#寫文件的實例向你全面介紹相關的內容。
C#寫文件操作在我們編程過程中的簡單需求實現,那么C#寫文件操作是如何實現的呢?C#寫文件操作的步驟以及需要注意的方面是什么呢?下面我們直接看看實現實例的內容:
C#寫文件操作實例:
- using System.IO; //引用系統文件
- namespace tools
- {
- public class WriteFiles()
- {
- public class WiteFiles()
- {
- //構造函數
- }
- public static void WriteLine(string format)
- {
- FileStream fs =
- new FileStream(Server.MapPath("log.txt"),
- FileMode.Append);
- StreamWriter streamWriter =
- new StreamWriter(fs);
- streamWriter.BaseStream.Seek(0, SeekOrigin.End);
- streamWriter.WriteLine(
- DateTime.Now.ToString(
- CultureInfo.CurrentCulture) + " " + format);
- streamWriter.Flush();
- }
- }
- }
C#寫文件操作之文件備注:
1 namespace 和class 可以不寫
2 直接在你想用寫文件的地方,在開始的using 中加上using System.IO
3 復制WriteLine方法即可
主要使用目的:
調試程序中使用,調用WriteLine(string format),輸出程序在執行過程中想要看的變量內容,根據log.txt的內容能知道程序是否按照coder的意愿執行。
C#寫文件操作的基本內容就向你介紹到這里,希望對你了解和學習C#寫文件操作有所幫助。
【編輯推薦】
責任編輯:仲衡
來源:
百度空間