我想在我的应用程序中压缩文件。有谁能告诉我确切的密码。我已经使用这个代码解压了文件:
我使用的是: ZipArchive.h
self.fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(@"document directory path:%@",paths);
self.documentDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/abc", self.documentDirectory];
NSLog(@"file path is:%@",filePath);
NSString *fileContent = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"data.zip"];
NSData *unzipData = [NSData dataWithContentsOfFile:fileContent];
[self.fileManager createFileAtPath:filePath contents:unzipData attributes:nil];
// here we go, unzipping code
ZipArchive *zipArchive = [[ZipArchive alloc] init];
if ([zipArchive UnzipOpenFile:filePath])
{
if ([zipArchive UnzipFileTo:self.documentDirectory overWrite:NO])
{
NSLog(@"Archive unzip success");
[self.fileManager removeItemAtPath:filePath error:NULL];
}
else
{
NSLog(@"Failure to unzip archive");
}
}
else
{
NSLog(@"Failure to open archive");
}
[zipArchive release];发布于 2013-09-11 20:05:37
您可以使用zipArchive创建zip文件。ZipArchive下载源代码并添加到您的应用程序文件夹中。
然后在头文件中添加:#import "ZipArchive/ZipArchive.h“
要创建一个zip文件很简单,只需使用以下代码:
BOOL ret = [zip CreateZipFile2:l_zipfile];
ret = [zip addFileToZip:l_photo newname:objectForZip];
if( ![zip CloseZipFile2] )
{
}
[zip release];发布于 2011-09-12 18:53:55
我使用SSZipArchive
NSError* error = nil;
BOOL ok = [SSZipArchive unzipFileAtPath:source_path toDestination:dest_path overwrite:YES password:nil error:&error];
DLog(@"unzip status: %i %@", (int)ok, error);
if(ok) {
[self performSelectorOnMainThread:@selector(unzipCompleted) withObject:nil waitUntilDone:NO];
} else {
[self performSelectorOnMainThread:@selector(unzipFailed:) withObject:error waitUntilDone:YES];
}发布于 2011-09-12 18:52:47
你会在这里得到你的答案。这是一个基于c语言的库,您可以通过它以编程方式压缩和解压缩文件。http://stackoverflow.com/questions/1546541/how-can-we-unzip-a-file-in-objective-c
https://stackoverflow.com/questions/7386695
复制相似问题