1、C#讀文件
按行讀取文件:
public void Read(string path)
{
StreamReader sr = new StreamReader(path,Encoding.Default);
String line;
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line.ToString());
}
}
2、寫文件
public void Write(string path)
{
FileStream fs = new FileStream(path, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
//開始寫入
sw.Write("Hello World!!!!");
//清空緩衝區
sw.Flush();
//關閉流
sw.Close();
fs.Close();
}