using System.IO;
1、寫入文本
File.WriteAllLines(@"d:\test.txt",lines);
File.WriteAllText(@"d:\text.txt",text);
using (StreamWriter writer = new StreamWriter(@"d:\text.txt",true))
{
foreach (string line in lines)
{
if (!line.Contains("second"))
{
writer.WriteLine(line);
}
}
}
2、讀取檔案
string s = File.ReadAllText(@"d:\text.txt");
string[] ls = File.ReadAllLines(@"d:\text.txt");
int counter = 0;
string current;
StreamReader reader = new StreamReader(@"d:\text.txt");
while((current=reader.ReadLine())!=null){
Console.WriteLine(current);
counter++;
reader.Close();