A03_IO文件管理

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace A03_IOFileManagement
{
    class Demo5
    {
        private string _Path1 = @"E:\test1.txt";
        private string _Path2 = @"D:\test1.txt";

        //創建文件
        public void Test1()
        {
            File.Create(_Path1);
        }

        //刪除文件
        public void Test2()
        {
            File.Delete(_Path1);
        }

        //移動(剪切)
        public void Test3()
        {
            File.Move(_Path1, _Path2);
        }

        //文件是否存在
        public void Test4()
        {
            bool bIsExists = File.Exists(_Path2);
            Console.WriteLine(bIsExists);
        }

        //文件的拷貝
        //默認不支持覆蓋操作
        public void Test5()
        {
            File.Copy(_Path2, _Path1);
            //File.Copy(_Path2, _Path1,true);  //第三個參數表示是否支持覆蓋操作。
        }

        static void Main3(string[] args)
        {
            Demo5 obj = new Demo5();
            //obj.Test1();
            //obj.Test2();
            //obj.Test3();
            //obj.Test4();
            obj.Test5();
        }
    }
}





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章