1 /// <summary>
2 /// 文件分割方法
3 /// </summary>
4 /// <param name="sourceFile">要分割的文件</param>
5 /// <param name="desDir">目标目录</param>
6 /// <param name="TempExtra">分割后的小文件名</param>
7 public void SplitFile(string sourceFile,string desDir, string[] TempExtra)
8 {
9 int iFileSize = 9 * 1024;
10 if (Directory.Exists(desDir))
11 Directory.Delete(desDir, true);
12 else
13 Directory.CreateDirectory(desDir);
14 FileStream SplitFileStream = new FileStream(sourceFile, FileMode.Open);
15 BinaryReader SplitFileReader = new BinaryReader(SplitFileStream);
16 byte[] TempBytes;
17 int iFileCount = (int)(SplitFileStream.Length / iFileSize);
18 if (SplitFileStream.Length % iFileSize != 0) iFileCount++;
19 for (int i = 1; i <= iFileCount; i++)
20 {
21 string sTempFileName = desDir + @"" + i.ToString().PadLeft(4, '0') + "." + TempExtra[TempExtra.Length - 1];
22
23 FileStream TempStream = new FileStream(sTempFileName, FileMode.OpenOrCreate);
24 BinaryWriter TempWriter = new BinaryWriter(TempStream);
25 TempBytes = SplitFileReader.ReadBytes(iFileSize);
26 TempWriter.Write(TempBytes);
27 TempWriter.Close();
28 TempStream.Close();
29 }
30 SplitFileReader.Close();
31 SplitFileStream.Close();
32 }