亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#文件分割的方法

 更新時間:2015年07月06日 15:49:39   作者:DTC2  
這篇文章主要介紹了C#文件分割的方法,針對小于等于64M文件和大于64M文件兩種情況分析了C#文件分割的實現(xiàn)技巧,需要的朋友可以參考下

本文實例講述了C#文件分割的方法。分享給大家供大家參考。具體如下:

1. 小文件分割(適用于小于等于64M的文件):

using System;
using System.IO;
string filetosplit=@"C:\temp\data.bin";
string targetpath=@"D:\store";
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();
int splitcount=3;
long PartLength=FileLength/splitcount+FileLength%splitcount;
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();
}

2. 大文件分割(適用于大于64M的文件)

using System;
using System.IO
string filetosplit=@"C:\temp\data.bin";
string targetpath=@"D:\store";
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();
int splitcount=3;
long PartLength=FileLength/splitcount+FileLength%splitcount;
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);
  long bc=byteCount;
  long PartCount=i<nCount?PartLength:FileLength-bc;
  int PartBufferCount=(int)(PartCount<int.MaxValue/32?PartCount:int.MaxValue/32);
  int nc=(int)Math.Ceiling((double)PartCount/PartBufferCount);
  for(int j=1;j<=nc;j++,bc=(j<nCount?bc+PartBufferCount:PartCount-PartBufferCount))
    fsw.Write(btArr, (int)bc, (int)(j<nc?PartBufferCount:PartCount-bc));
  fsw.Flush();
  fsw.Close();
}
fsr.Close();

希望本文所述對大家的C#程序設計有所幫助。

相關(guān)文章

  • C#使用隨機數(shù)編寫班級點名器的示例代碼

    C#使用隨機數(shù)編寫班級點名器的示例代碼

    本文主要介紹了C#使用隨機數(shù)編寫班級點名器的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-05-05
  • C#實現(xiàn)斐波那契數(shù)列的幾種方法整理

    C#實現(xiàn)斐波那契數(shù)列的幾種方法整理

    這篇文章主要介紹了C#實現(xiàn)斐波那契數(shù)列的幾種方法整理,主要介紹了遞歸,循環(huán),公式和矩陣法等,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-09-09
  • C#通過鏈表實現(xiàn)隊列的方法

    C#通過鏈表實現(xiàn)隊列的方法

    這篇文章主要介紹了C#通過鏈表實現(xiàn)隊列的方法,涉及C#操作鏈表的相關(guān)技巧,需要的朋友可以參考下
    2015-04-04
  • C#中DataTable實現(xiàn)篩選查詢的示例

    C#中DataTable實現(xiàn)篩選查詢的示例

    本文主要介紹了C#中DataTable實現(xiàn)篩選查詢的示例,主要是DataTable進行過濾篩選,常用的一些方法為:Select,dataview,具有一定的參考價值,感興趣的可以了解一下
    2023-04-04
  • Unity3D選擇本地圖片并加載

    Unity3D選擇本地圖片并加載

    這篇文章主要為大家詳細介紹了Unity3D選擇本地圖片并加載,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • C#實現(xiàn)的xml操作類完整實例

    C#實現(xiàn)的xml操作類完整實例

    這篇文章主要介紹了C#實現(xiàn)的xml操作類,包含C#針對xml的創(chuàng)建、刪除、遍歷、插入等常見操作,需要的朋友可以參考下
    2016-06-06
  • C#之Expression表達式樹實例

    C#之Expression表達式樹實例

    這篇文章主要介紹了C#之Expression表達式樹,包括了表達式樹的原理與用法技巧,需要的朋友可以參考下
    2014-10-10
  • unity 鼠標移入彈出UI的操作

    unity 鼠標移入彈出UI的操作

    這篇文章主要介紹了unity 鼠標移入彈出UI的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04
  • C#中的那些常用加密算法

    C#中的那些常用加密算法

    本文主要講解一下C#常用的那些加密算法,包括MD5加密、SHA1加密、Base64加密、Des加密、RSA加密等,需要的朋友可以參考下
    2020-11-11
  • 經(jīng)典的委托排序(深入分析)

    經(jīng)典的委托排序(深入分析)

    本篇文章是對委托排序進行了詳細的分析介紹,需要的朋友參考下
    2013-06-06

最新評論