C# - 接近文件顶部

时间:2015-05-22 18:33:58

标签: c#

我想打开一个文件,追加文件的第一行然后关闭文件。这是我一直在研究的代码。我放置了一个附加代码,但它只是放在底部,我希望它在顶部。请帮帮忙?

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

            }
        }
    }
}

0 个答案:

没有答案