C#文件分割
来源:互联网 发布:股票走势软件 编辑:程序博客网 时间:2024/06/05 11:38
http://www.oschina.net/code/snippet_222150_8303
[代码] 文件分割(适合小文件,小于等于64MB)
01
using
System;
02
using
System.IO;
03
string
filetosplit=
@"C:\temp\data.bin"
;
04
string
targetpath=
@"D:\store"
;
05
FileStream fsr =
new
FileStream(filetosplit, FileMode.Open, FileAccess.Read);
06
long
FileLength=fsr.Length;
07
byte
[] btArr =
new
byte
[FileLength];
08
fsr.Read(btArr, 0, (
int
)FileLength);
09
fsr.Close();
10
int
splitcount=3;
11
long
PartLength=FileLength/splitcount+FileLength%splitcount;
12
int
nCount=(
int
)Math.Ceiling((
double
)FileLength/PartLength);
13
string
strFileName=Path.GetFileName(filetosplit);
14
long
byteCount=0;
15
for
(
int
i=1;i<=nCount;i++,byteCount=(i<nCount?byteCount+PartLength:FileLength-PartLength))
16
{
17
FileStream fsw =
new
FileStream(targetpath + Path.DirectorySeparatorChar+ strFileName +i, FileMode.Create, FileAccess.Write);
18
fsw.Write(btArr, (
int
)byteCount, (
int
)(i<nCount?PartLength:FileLength-byteCount));
19
fsw.Flush();
20
fsw.Close();
21
}
[代码] 文件分割(适合大文件,大于64MB)
01
using
System;
02
using
System.IO
03
string
filetosplit=
@"C:\temp\data.bin"
;
04
string
targetpath=
@"D:\store"
;
05
FileStream fsr =
new
FileStream(filetosplit, FileMode.Open, FileAccess.Read);
06
long
FileLength=fsr.Length;
07
byte
[] btArr =
new
byte
[FileLength];
08
fsr.Read(btArr, 0, (
int
)FileLength);
09
fsr.Close();
10
int
splitcount=3;
11
long
PartLength=FileLength/splitcount+FileLength%splitcount;
12
int
nCount=(
int
)Math.Ceiling((
double
)FileLength/PartLength);
13
string
strFileName=Path.GetFileName(filetosplit);
14
long
byteCount=0;
15
for
(
int
i=1;i<=nCount;i++,byteCount=(i<nCount?byteCount+PartLength:FileLength-PartLength))
16
{
17
FileStream fsw =
new
FileStream(targetpath + Path.DirectorySeparatorChar+ strFileName +i, FileMode.Create, FileAccess.Write);
18
long
bc=byteCount;
19
long
PartCount=i<nCount?PartLength:FileLength-bc;
20
int
PartBufferCount=(
int
)(PartCount<
int
.MaxValue/32?PartCount:
int
.MaxValue/32);
21
int
nc=(
int
)Math.Ceiling((
double
)PartCount/PartBufferCount);
22
for
(
int
j=1;j<=nc;j++,bc=(j<nCount?bc+PartBufferCount:PartCount-PartBufferCount))
23
fsw.Write(btArr, (
int
)bc, (
int
)(j<nc?PartBufferCount:PartCount-bc));
24
fsw.Flush();
25
fsw.Close();
26
}
27
fsr.Close();
- C#文件分割
- C# 文件分割符
- C#版文件分割器
- c#读写tif文件,分割tif文件
- 文件分割与合并(C# Winforms)
- c#文件分割与合并 part 2
- C#文件的分割与合并
- C#实现上传文件分割,断点续传上传文件
- 用C#设计一个命令行方式的文件分割器
- 用C#设计一个命令行方式的文件分割器
- 用C#设计一个命令行方式的文件分割器
- c#文件分割与合并 part 1 (转自互联网)
- 分割文件
- 文件分割
- 文件分割
- 文件分割
- 文件分割
- 文件分割
- C#常用操作
- java笔记2:java静态导入
- 漫谈Web Service工作原理及.NET平台的实现机制
- self-introduction
- 如何在Excel 中使用日期与时间
- C#文件分割
- java第七课_多态
- C#文件合并
- linux学习心得(二)
- Linux Learning Notes in learning Linux 鸟哥的私房菜 Chapter5
- 生成模型与判别模型
- 一个整数,它加上100后是一个完全平方数,加上168又是一个完全平方数,请问该数是多少?
- Python 中方法参数 * 和 ** 的例子
- VirtualBox虚拟机网络设置