IOS解压缩和压缩文件

来源:互联网 发布:java 高级程序员 书 编辑:程序博客网 时间:2024/06/05 22:39
以前提到过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

0 0
原创粉丝点击