from the zip file not able to fetch data from the document directory

落花浮王杯 提交于 2019-12-11 07:14:43

问题


i am downloading a zip file and saving in document directory. and then making unzip using the ssziparchive . but not getting any data from the zip file .how to fetch the data .and i am not able to see where is my unzip file .in document directory only i am getting this.

i have used this code to make zip as un zip file

NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:@"image.zip"];
    NSString *zipPath =fullPath;
    NSString *destinationPath =[documentsDirectory  stringByAppendingPathComponent:@"unZipimage"];
    NSLog(@"zip path==%@",zipPath);
    NSLog(@"dest path==%@",destinationPath);
  //
    [SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath];

回答1:


Zip Data store in Bundle To document directory as below.

  1. get Path from Bundle.

     NSString *StrZIP = [[NSBundle mainBundle] pathForResource:@"TestZIP" ofType:@"zip"];
    
  2. convert Zip To NSData

    NSData *ZIPData = [NSData dataWithContentsOfFile:StrZIP];
    
  3. Store Zip file in document directory

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
    NSString *filePath = [documentsPath stringByAppendingPathComponent:@"TestZIP.zip"]; //Add the file name
    [ZIPData writeToFile:filePath atomically:YES]; //Write the file
    
  4. TeztZIP is unzip using SSZipArchive at documentsPath

    [SSZipArchive unzipFileAtPath:filePath toDestination:documentsPath];
    

OUTPUT :



来源:https://stackoverflow.com/questions/28060790/from-the-zip-file-not-able-to-fetch-data-from-the-document-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!