IOS解压缩和压缩文件

以前提到过 Android解压缩zip的实现方式,现在讲解一下IOS中解压的方法。 

压缩文件: 

Java代码   收藏代码
  1. ZipArchive *zip = [[ZipArchive alloc] init];  
  2.   
  3. NSString *sZipPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.zip"];  
  4.   
  5. NSString *img1Path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/img1.jpg"] ;  
  6.   
  7. NSString* img2Path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/img2.jpg"] ;  
  8.   
  9. BOOL bRet = [zip CreateZipFile2:sZipPath];  
  10.   
  11. bRet = [zip addFileToZip:img1Path newname:@"img1.jpg"];  
  12.   
  13. bRet = [zip addFileToZip:img2Path newname:@"img2.jpg"];  
  14.   
  15. [zip CloseZipFile2];  
  16.   
  17. [zip release];  


解压缩: 

Java代码   收藏代码
  1. ZipArchive *zip = [[ZipArchive alloc] init];  
  2.   
  3. NSString *sZipPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.zip"];  
  4.   
  5. NSString *unZipTo = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test"];  
  6.   
  7. if ([zip UnzipOpenFile:sZipPath])  
  8.   
  9. {  
  10.   
  11. [zip UnzipFileTo:unZipTo overWrite:YES];  
  12.   
  13. [zip UnzipCloseFile];  
  14.   
  15. }  
  16.   
  17. [zip release];  


ZipArchive资源下载地址: 

http://code.google.com/p/ziparchive/downloads/detail?name=ZipArchive.zip

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值