C#:分割成功

   以前有看过某些游戏,或者是自己的小研究,就是数据有个索引,然后根据这个索引读取文件。
   至少,DS模拟人生就是其中一个。

   今天写了分割软件,成功将整合的文件根据索引分割了。
   分割前的原文件26MB左右,分割后,占空间达120MB之多。
   小文件是罪魁祸首啊!

   附上关键部分C#代码:
  1. int IndexLen = bFileIndex.ReadInt32() / 4;
  2.  strFileIndex.Position = 0x0;
  3.  
  4.  //读取索引
  5.  int[] BinIndex = new int[IndexLen];
  6.  for (int i = 0; i < IndexLen; i++)
  7.  {
  8.  BinIndex[i] = bFileIndex.ReadInt32();
  9.  }
  10.  
  11.  //计算小文件长度
  12.  int[] BinLen = new int[IndexLen - 1];
  13.  for (int y = 0; y < (IndexLen - 1); y++)
  14.  {
  15.  BinLen[y] = BinIndex[y + 1] - BinIndex[y];
  16.  }
  17.  
  18.  for (int i = 0; i < IndexLen - 1; i++)
  19.  {
  20.  string TempFileName = fPath + fPathName + "\" + i.ToString().PadLeft(5, '0') + ".bin";
  21.  FileStream TempStream = new FileStream(TempFileName, FileMode.OpenOrCreate);
  22.  BinaryWriter TempWriter = new BinaryWriter(TempStream);
  23.  byte[] TmpBytes = bFileIndex.ReadBytes(BinLen[i]);
  24.  TempWriter.Write(TmpBytes);
  25.  TempWriter.Close();
  26.  TempStream.Close();

2007-12-6 19:30:27
引用通告地址: 点击获取引用地址
标签: 编程 C#
评论: 0 | 引用: 0 | 阅读: 557
 加入网摘
发表评论
昵 称(*): 密 码:
网 址: 邮 箱:
选 项:    
内 容(*):