1

zip ファイルをダウンロードしてドキュメント ディレクトリに保存しています。ssziparchiveを使用して解凍します。しかし、zipファイルからデータを取得していません.データを取得する方法.そして、解凍ファイルがどこにあるかを確認できません.ドキュメントディレクトリでのみ、これを取得しています. ここに画像の説明を入力

このコードを使用して、zipをun zipファイルとして作成しました

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

1 に答える 1

1

以下のように、Bundle To ドキュメント ディレクトリ内の Zip データ ストア。

  1. バンドルからパスを取得します。

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

    NSData *ZIPData = [NSData dataWithContentsOfFile:StrZIP];
    
  3. Zipファイルをドキュメントディレクトリに保存

    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 はSSZipArchiveat documentsPathを使用して解凍されます

    [SSZipArchive unzipFileAtPath:filePath toDestination:documentsPath];
    

出力:

ここに画像の説明を入力

于 2015-01-21T06:59:45.983 に答える