//文本文件创建、读写、删除
string path = @"F:\FILE.txt";
if (!File.Exists(path))
{
//创建、写
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("大琳仔");
}
}
//追加
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine("小琳仔");
}
//读
string s;
using (StreamReader sr = File.OpenText(path))
{
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
//拷贝
try
{
File.Copy(path,@"F:\F.txt");
}
catch (Exception e)
{
Console.WriteLine("拷贝失败:" + e.Message);
}
//删除
try
{
File.Delete(path);
}
catch(Exception e)
{
Console.WriteLine("删除失败:"+e.Message);
}