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();
}
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
C#写文件操作之文件备注:
1 namespace 和class 可以不写
2 直接在你想用写文件的地方,在开始的using 中加上using System.IO
3 复制WriteLine方法即可
主要使用目的:
调试程序中使用,调用WriteLine(string format),输出程序在执行过程中想要看的变量内容,根据log.txt的内容能知道程序是否按照coder的意愿执行。
C#写文件操作的基本内容就向你介绍到这里,希望对你了解和学习C#写文件操作有所帮助。
【编辑推荐】