从zip文件中无法从文档目录中获取数据 [英] from the zip file not able to fetch data from the document directory

查看:61
本文介绍了从zip文件中无法从文档目录中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在下载一个zip文件并保存在文档目录中.然后使用 ssziparchive 解压缩.但没有从zip文件中获取任何数据.如何获取数据.我无法看到我的解压缩文件在文档目录中的位置,只有我正在获取此文件.

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.

我已使用此代码将zip压缩为un zip文件

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];

推荐答案

将数据包中的数据包压缩到文档目录,如下所示.

Zip Data store in Bundle To document directory as below.

  1. 从捆绑包中获取路径.

  1. get Path from Bundle.

 NSString *StrZIP = [[NSBundle mainBundle] pathForResource:@"TestZIP" ofType:@"zip"];

  • 邮政编码转换为 NSData

    NSData *ZIPData = [NSData dataWithContentsOfFile:StrZIP];
    

  • 将Zip文件存储在文档目录中

  • 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
    

  • TeztZIP在文档路径中使用 SSZipArchive 解压缩

    [SSZipArchive unzipFileAtPath:filePath toDestination:documentsPath];
    

  • 输出:

    这篇关于从zip文件中无法从文档目录中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆