IOS解压缩和压缩文件

来源:互联网 发布:高性能网络编程2 编辑:程序博客网 时间:2024/05/20 14:40

IOS中解压的方法

压缩文件:

ZipArchive *zip = [[ZipArchive alloc] init];

NSString *sZipPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.zip"];

NSString *img1Path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/img1.jpg"] ;

NSString* img2Path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/img2.jpg"] ;

BOOL bRet = [zip CreateZipFile2:sZipPath];

bRet = [zip addFileToZip:img1Path newname:@"img1.jpg"];

bRet = [zip addFileToZip:img2Path newname:@"img2.jpg"];

[zip CloseZipFile2];

[zip release];

解压缩:

ZipArchive *zip = [[ZipArchive alloc] init];

NSString *sZipPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.zip"];

NSString *unZipTo = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test"];

if ([zip UnzipOpenFile:sZipPath])

{

[zip UnzipFileTo:unZipTo overWrite:YES];

[zip UnzipCloseFile];

}

[zip release];


原创粉丝点击