我想打开一个文件,追加文件的第一行然后关闭文件。这是我一直在研究的代码。我放置了一个附加代码,但它只是放在底部,我希望它在顶部。请帮帮忙?
string path = "textFile1";
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("Hello");
sw.WriteLine("And");
sw.WriteLine("Welcome");
}
}
using (StreamWriter sw = File.AppendText(path, Environment.))
{
sw.WriteLine("This");
sw.WriteLine("is Extra");
sw.WriteLine("Text");
}
//opens the file to read from
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
System.Threading.Thread.Sleep(200);
}
}
}
}