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();