此代码允许您解压缩文件并在文档中创建一个文件夹让我们说List和此List文件夹现在拥有所有解压缩数据如何访问列表内容 ??
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *saveLocation =
[documentsDirectory stringByAppendingString:@"myfile.zip"];
NSFileManager* fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:saveLocation]) {
[fileManager removeItemAtPath:saveLocation error:nil];
NSLog(@" file path %@",fileManager);
}
NSURLRequest *theRequest =
[NSURLRequest requestWithURL:
[NSURL URLWithString:@"http://localhost/list.zip"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSData *received =
[NSURLConnection sendSynchronousRequest:theRequest
returningResponse:nil error:nil];
if ([received writeToFile:saveLocation atomically:TRUE]) {
NSString *cmd =
[NSString stringWithFormat:@"unzip \"%@\" -d\"%@\"",
saveLocation, documentsDirectory];
// Here comes the magic...
system([cmd UTF8String]);
}
NSLog(@"loca is %@", saveLocation);
NSLog(@"%@", [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil]); // i can see list folder but how to get the content outside??
答案 0 :(得分:1)
在iphone上解压缩文件阅读此内容 - http://www.touch-code-magazine.com/update-dynamically-your-iphone-app-with-new-content/
答案 1 :(得分:0)
您可以使用NSFileManager
的
- (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error
。