码迷,mamicode.com
首页 > 其他好文 > 详细

大文件拷贝

时间:2016-01-23 21:38:05      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

Thread th = new Thread(() =>
            { 
               
               // Directory.p

                if (!File.Exists(this.textBox1.Text))
                {
                    MessageBox.Show("拷贝的文件路劲有问题");
                    return;
                }
                else
                {

                    CheckForIllegalCrossThreadCalls = false;
                    using (FileStream fs = new FileStream(this.textBox1.Text, FileMode.Open))
                    {
                        byte[] by = new byte[1024 * 1024];
                        long len = fs.Length;
                        int i = fs.Read(by, 0, by.Length);
                        long j = 0;

                        using (FileStream fw = new FileStream(this.textBox2.Text, FileMode.Create))
                        {


                            while (i != 0)
                            {
                                fw.Write(by, 0, i);
                                i = fs.Read(by, 0, by.Length);
                                j += i;
                                progressBar1.Value = (int)(j * 100 / len);

                            }
                        }


                    }
                    progressBar1.Value = 100;
                    this.button4.Text = "ok";
                    GC.Collect();
                }
              
            });


            th.Start();

  

大文件拷贝

标签:

原文地址:http://www.cnblogs.com/xh0626/p/5153928.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!