zoukankan      html  css  js  c++  java
  • FileStream类操作文件

      private void buttonselect_Click (object sender, EventArgs e)
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Title = "请选择要复制的文件";
                ofd.InitialDirectory = @"C:UsersSpringRainDesktop";
                ofd.Filter = "所有文件|*.*";
                ofd.ShowDialog();
                textBoxSelect.Text = ofd.FileName;
            }

            private void buttonsave_Click (object sender, EventArgs e)
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title = "请选择要保存文件的路径";
                sfd.InitialDirectory = @"C:UsersSpringRainDesktop";
                sfd.Filter = "所有文件|*.*";
                sfd.ShowDialog();
                textBoxSave.Text = sfd.FileName;
                //先读取 再写入
                using (FileStream fsRead = new FileStream(textBoxSelect.Text.Trim(), FileMode.OpenOrCreate, FileAccess.Read))
                {
                    using (FileStream fsWrite = new FileStream(textBoxSave.Text.Trim(), FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        //设置进度条
                        progressBarFile.Maximum = (int)fsRead.Length;

                        byte[] buffer = new byte[1024 * 1024 * 3];
                        while (true)
                        {
                            int r = fsRead.Read(buffer, 0, buffer.Length);
                            if (r == 0)
                            {
                                break;
                            }
                         
                            fsWrite.Write(buffer, 0, r);
                            progressBarFile.Value = (int)fsWrite.Length;
                        }

                        MessageBox.Show("保存成功");

                    }
                }

      

  • 相关阅读:
    教你解决Python爬虫的时候Xpath取值为空
    jmeter工具使用心得
    查找uipath项目中引用包的目录
    pandas 设置某列值的类型,求和指定列,给指定列赋值
    pandas 获取不符合条件/不包含某个字符串的dataframe
    Visual Studio清理最近項目和解決方案
    【vue BUG记录】作用域插槽
    银行下拉框数据
    as3.0对图片进行不规则切割源代码实例
    Vuforia+single image 问题
  • 原文地址:https://www.cnblogs.com/netlws/p/8886929.html
Copyright © 2011-2022 走看看