大文件拷贝

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

  

posted @ 2016-01-23 20:18  刀小爱  阅读(125)  评论(0编辑  收藏  举报