有谁能够提供关于 C# 读/写记录文件的源代码?

来源:百度知道 编辑:UC知道 时间:2024/05/04 10:16:21

demo:
读取文件:
using System;
using System.IO;

namespace readwriteapp
{
class Class1
{
[STAThread]
static void Main(string[] args)
{

String line;

try
{
//Pass the file path and file name to the StreamReader constructor
StreamReader sr = new StreamReader("C:\\boot.ini");

//Read the first line of text
line = sr.ReadLine();

//Continue to read until you reach end of file
while (line != null)
{
//write the lie to console window
Console.WriteLine(line);
//Read the next line
line = sr.ReadLine();
}

//close the file
sr.Close();
Console.ReadLine();
}
catch(Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
finally
{
Console.WriteLine(&