using System;
using System.IO;

class Test
{
    public static void Main()
    {
        string path = @"c:\testdir\MyTest.txt";
        if (!File.Exists(path))
        {
            using (StreamWriter sw = File.CreateText(path))
            {
                sw.WriteLine("Hello");
                sw.WriteLine("And");
                sw.WriteLine("Welcome");
            }
        }
        using (StreamReader sr = File.OpenText(path))
        {
            string s = "";
            while ((s = sr.ReadLine()) != null)
            {
                Console.WriteLine(s);
            }
        }
        try
        {
            string path2 = @"c:\testdir\MyTest.temp";
            // Ŀļڣɾ
            if (!File.Exists(path2)) File.Delete(path2);
            // ļָĿ¼
            File.Copy(path, path2);
            Console.WriteLine("{0} Ƶ {1}.", path, path2);
            // ɾ¸Ƶļ
            File.Delete(path2);
            Console.WriteLine("{0} ļѾɹɾ", path2);
        }
        catch (Exception e)
        {
            Console.WriteLine("ʧܣԭǣ{0}", e.ToString());
        }
        Console.ReadLine();
    }
}
