知行合一

享受过程 漠视结果

导航

文件复制

            FileStream fr = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read);
            FileInfo fi = new FileInfo(openFileDialog1.FileName);
            FileStream fw = new FileStream("f:\\"+fi.Name , FileMode.Create, FileAccess.Write);

            if (fr.CanRead)
            {
                long length = fr.Length;
                int size = 1024 * 1024;
                int count = (int)(length / size);
                int last = (int)(length % size);

                while (count > 0)
                {
                    byte[] buffer = new byte[size];
                    fr.Read(buffer, 0, buffer.Length);
                    fw.Write(buffer, 0, buffer.Length);
                    count--;
                }

                if (last > 0)
                {
                    byte[] buffer = new byte[last];
                    fr.Read(buffer, 0, buffer.Length);
                    fw.Write(buffer, 0, buffer.Length);
                }

                fr.Close();
                fw.Flush();
                fw.Close();
                MessageBox.Show("Done!");
            }

 

posted on 2012-12-26 14:48  项羽  阅读(185)  评论(0编辑  收藏  举报