自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iOS使用ZipArchive壓縮文件

移動(dòng)開發(fā) iOS
今天開發(fā)應(yīng)用需要使用到壓縮文件功能,在網(wǎng)上查找了一下相關(guān)資料,發(fā)現(xiàn)ZipArchive使用相對(duì)簡單點(diǎn),自己就寫了個(gè)demo分享給大家。

今天開發(fā)應(yīng)用需要使用到壓縮文件功能,在網(wǎng)上查找了一下相關(guān)資料,發(fā)現(xiàn)ZipArchive使用相對(duì)簡單點(diǎn),自己就寫了個(gè)demo函數(shù):

ZipArchive下載地址:https://code.google.com/p/ziparchive/

代碼:

  1. +(NSString *)zipFiles:(NSArray *)paramFiles   
  2.  {   
  3.      //生成zip文件名字   
  4.      NSString * zipFileName = [[CUtils generateRndString] stringByAppendingPathExtension:@"zip"];   
  5.      //取得zip文件全路徑   
  6.      NSString * zipPath = [[CUtils documentPath] stringByAppendingPathComponent:zipFileName];           
  7.      //判斷文件是否存在,如果存在則刪除文件   
  8.      NSFileManager * fileManager = [NSFileManager defaultManager];   
  9.      @try  
  10.      {   
  11.          if([fileManager fileExistsAtPath:zipPath])   
  12.          {   
  13.              if(![fileManager removeItemAtPath:zipPath error:nil])   
  14.              {   
  15.                  CCLog(@"Delete zip file failure.");   
  16.              }   
  17.          }   
  18.      }   
  19.      @catch (NSException * exception) {   
  20.          CCLog(@"%@",exception);   
  21.      }   
  22.      //判斷需要壓縮的文件是否為空   
  23.      if(paramFiles == nil || [paramFiles count] == 0)   
  24.      {   
  25.          CCLog(@"The files want zip is nil.");   
  26.          return nil;   
  27.      }           
  28.      //實(shí)例化并創(chuàng)建zip文件   
  29.      ZipArchive * zipArchive = [[ZipArchive alloc] init];   
  30.      [zipArchive CreateZipFile2:zipPath];          
  31.      //遍歷文件   
  32.      for(NSString * fileName in paramFiles)   
  33.      {   
  34.          NSString * filePath = [[CUtils documentPath] stringByAppendingPathComponent:fileName];   
  35.          if([fileManager fileExistsAtPath:filePath])   
  36.          {   //添加文件到壓縮文件   
  37.              [zipArchive addFileToZip:filePath newname:fileName];   
  38.          }   
  39.      }   
  40.      //關(guān)閉文件   
  41.      if([zipArchive CloseZipFile2])   
  42.      {   
  43.          CCLog(@"Create zip file success.");   
  44.          [zipArchive release];   
  45.          return zipPath;   
  46.      }   
  47.      [zipArchive release];   
  48.      return nil;   
  49.  }  

ps:代碼里面使用的CCLog是自定義

責(zé)任編輯:閆佳明 來源: oschina
相關(guān)推薦

2011-04-08 09:42:19

Access數(shù)據(jù)庫壓縮文件

2009-12-16 16:11:14

Linux壓縮文件

2009-12-25 17:55:05

Linux tar

2022-07-04 08:03:08

Go壓縮打包

2018-09-14 16:18:26

Linux壓縮文件應(yīng)用程序

2012-05-10 09:43:28

2024-05-23 11:33:42

python代碼開發(fā)

2015-08-07 10:02:34

Java線程池遞歸

2020-05-07 09:18:57

Linux壓縮文件命令

2009-04-27 13:46:30

網(wǎng)絡(luò)管理拷貝故障

2010-03-03 13:32:08

Python壓縮文件

2009-12-03 14:10:06

PHP壓縮文件夾

2020-11-08 14:37:46

Python壓縮文件代碼

2009-06-06 19:07:44

java壓縮文件

2011-09-15 10:12:11

ubunturar

2019-04-26 09:50:21

Linux壓縮文件文件夾

2023-06-01 09:38:27

微軟WinRARWindows 11

2024-01-04 12:47:00

Linux命令工具

2009-11-30 09:31:41

Windows 7文件解壓

2019-10-24 08:52:23

Linux壓縮文件歸檔
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)