C#实现一次分割多个文件
2018-07-20 来源:open-open
using System.IO; using System.Windows.Forms; OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter ="All files (*.*)|*.*"; dlg.FilterIndex = 1; dlg.RestoreDirectory = true; dlg.Multiselect = true; if (dlg.ShowDialog() == DialogResult.OK) { foreach (string filetosplit in dlg.FileNames) { string targetpath="D:"; FileStream fsr = new FileStream(filetosplit, FileMode.Open, FileAccess.Read); long FileLength=fsr.Length; byte[] btArr = new byte[FileLength]; fsr.Read(btArr, 0, (int)FileLength); fsr.Close(); long PartLength=FileLength/3+FileLength%3; int nCount=(int)Math.Ceiling((double)FileLength/PartLength); string strFileName=Path.GetFileName(filetosplit); long byteCount=0; for(int i=1;i<=nCount;i++,byteCount=(i<nCount?byteCount+PartLength:FileLength-PartLength)) { FileStream fsw = new FileStream(targetpath + Path.DirectorySeparatorChar+ strFileName +i, FileMode.Create, FileAccess.Write); fsw.Write(btArr, (int)byteCount, (int)(i<nCount?PartLength:FileLength-byteCount)); fsw.Flush(); fsw.Close(); } fsr.Close(); } }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:PHP 下载远程文件
下一篇:PHP 防止 SQL 注入的函数
最新资讯
热门推荐