博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
读写,复制文件
阅读量:7226 次
发布时间:2019-06-29

本文共 1274 字,大约阅读时间需要 4 分钟。

namespace Homework

{

public partial class Form1 : Form

{
public Form1()
{
InitializeComponent();
}
string pathSource = string.Empty;
string pathMB = string.Empty;
private void btnOpenPath_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = false;
ofd.ShowDialog();
pathSource = ofd.FileName;
txtSourcePath.Text = pathSource;
}

private void btnXz_Click(object sender, EventArgs e)

{
if (!string.IsNullOrEmpty(pathSource))
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.CheckPathExists = true;
sfd.FileName = Path.GetFileNameWithoutExtension(pathSource);
sfd.DefaultExt = Path.GetExtension(pathSource);
sfd.ShowDialog();
pathMB = sfd.FileName;
txtTargetPath.Text = pathMB;
}
}

private void button1_Click(object sender, EventArgs e)

{
if (File.Exists(pathSource))
{
CopyTo();
// CopyTo(pathSource, pathMB);
}
}
private void CopyTo()
{
using (FileStream fsRead = new FileStream(pathSource, FileMode.Open))
{
using (FileStream fsWrite = new FileStream(pathMB, FileMode.Create))
{
while (true)
{
byte[] bytes = new byte[1024 * 50 * 1024];
int count = fsRead.Read(bytes, 0, bytes.Length);
fsWrite.Write(bytes, 0, count);
if (count <= 0)
{
MessageBox.Show("OK");
break;
}
}
}
}
}
}
}

转载于:https://www.cnblogs.com/wrnsweet/p/6177888.html

你可能感兴趣的文章
MySQL无法启动几种常见问题小结
查看>>
阿里CTO:阿里所有技术和产品输出都将必须通过阿里云进行
查看>>
更好用的集群限流功能,Sentinel 发布 v1.4.2
查看>>
Python(生成执行文件)
查看>>
redis安装配置 - ttlsa教程系列之redis
查看>>
Linux --DHCP服务器配置;DHCP服务器中继
查看>>
IE版本多的可爱_已迁移
查看>>
eclipse查看jar包中class的中文注释乱码问题的解决
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
mariadb安装
查看>>
vue+vuex+axios+echarts画一个动态更新的中国地图
查看>>
5.8 volumetric post-processing--game programming gems5 笔记
查看>>
8086的地址空间
查看>>
Android开发动画效果被遮掉的解决方法
查看>>
Apache2.2.17源码编译安装以及配置虚拟主机
查看>>
2017年开发语言排名
查看>>
读二进制表的显示 Binary Watch
查看>>
我的友情链接
查看>>
linux基础:10、基础命令(4)
查看>>