zoukankan      html  css  js  c++  java
  • 读写,复制文件

    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;
    }
    }
    }
    }
    }
    }
    }

  • 相关阅读:
    JSOI2010 满汉全席
    LNOI2014 LCA
    BZOJ3689 异或之
    Codeforces Round #553 div.2
    AHOI2013 差异
    SDOI2016 生成魔咒
    NOI2006 最大获利
    没有过的题QAQ
    NOI2014 动物园
    HDU4622 Reincarnation
  • 原文地址:https://www.cnblogs.com/wrnsweet/p/6177888.html
Copyright © 2011-2022 走看看