[C#] 一次分割多个文件 →→→→→进入此内容的聊天室

来自 , 2019-03-19, 写在 C#, 查看 124 次.
URL http://www.code666.cn/view/2e09926f
  1. using System.IO;
  2. using System.Windows.Forms;
  3.  
  4. OpenFileDialog dlg = new OpenFileDialog();
  5. dlg.Filter ="All files (*.*)|*.*";
  6. dlg.FilterIndex = 1;
  7. dlg.RestoreDirectory = true;
  8. dlg.Multiselect = true;
  9. if (dlg.ShowDialog() == DialogResult.OK)
  10. {
  11.     foreach (string filetosplit in dlg.FileNames)
  12.     {
  13.                         string targetpath="D:";
  14.                         FileStream fsr = new FileStream(filetosplit, FileMode.Open, FileAccess.Read);
  15.                         long FileLength=fsr.Length;
  16.                         byte[] btArr = new byte[FileLength];
  17.                         fsr.Read(btArr, 0, (int)FileLength);
  18.                         fsr.Close();
  19.                         long PartLength=FileLength/3+FileLength%3;
  20.                         int nCount=(int)Math.Ceiling((double)FileLength/PartLength);
  21.                         string strFileName=Path.GetFileName(filetosplit);
  22.                         long byteCount=0;
  23.                         for(int i=1;i<=nCount;i++,byteCount=(i<nCount?byteCount+PartLength:FileLength-PartLength))
  24.                         {
  25.                                 FileStream fsw = new FileStream(targetpath + Path.DirectorySeparatorChar+ strFileName +i, FileMode.Create, FileAccess.Write);
  26.                                 fsw.Write(btArr, (int)byteCount, (int)(i<nCount?PartLength:FileLength-byteCount));
  27.                                 fsw.Flush();
  28.                                 fsw.Close();
  29.                         }
  30.                         fsr.Close();
  31.     }
  32. }
  33. //csharp/1122

回复 "一次分割多个文件"

这儿你可以回复上面这条便签

captcha