A06_大文件拷贝

来源:互联网 发布:mac 用户主目录在哪里 编辑:程序博客网 时间:2024/06/05 17:26

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.IO;namespace A06_CopyBigFileByFileStream{    class Demo8    {        //原始路径        private string _StrSourcePath = @"D:\THE HERO!!~怒れる拳に火をつけろ~ (TV Size) (OP主題歌).mp3";        //目标路径        private string _StrTargetPath = @"E:\THE HERO!!~怒れる拳に火をつけろ~ (TV Size) (OP主題歌).mp3";        private int _IntLoadCount = 0;        /// <summary>        /// 实现大文件拷贝        /// </summary>        public void Test1()        {            if (File.Exists(_StrSourcePath))            {                //读文件流                using (FileStream fsRead = new FileStream(_StrSourcePath, FileMode.Open))                {                    using (FileStream fsWrite = new FileStream(_StrTargetPath, FileMode.OpenOrCreate))                    {                            byte[] byArrayRead = new byte[1024 * 1024]; //1M空间                        while (true)                        {                            //加载计数                            Console.Write(" " + (++_IntLoadCount));                            //读取                            int readCont = fsRead.Read(byArrayRead, 0, byArrayRead.Length);                            //写入                            fsWrite.Write(byArrayRead, 0, readCont);                            //判断是否为最后一次读取                            if (readCont<byArrayRead.Length)                            {                                break;                            }                        }                    }                }            }            else            {                Console.WriteLine("原路径不存在");            }            //读取文件流        }        static void Main(string[] args)        {            Demo8 obj = new Demo8();            obj.Test1();        }    }}