zoukankan      html  css  js  c++  java
  • 使用SSZipArchive第三方库解压zip包

    //
    //  ViewController.m
    //  解压缩zip包开发
    //
    //  Created by 张凯泽 on 16/3/9.
    //  Copyright © 2016年 rytong_zkz. All rights reserved.
    //
    
    #import "ViewController.h"
    #import "SSZipArchive.h"
    @interface ViewController ()
    - (IBAction)PressZipClick:(id)sender;
    - (IBAction)UnarchiveZipClick:(id)sender;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
    }
    
    //压缩zip包
    - (IBAction)PressZipClick:(id)sender {
        NSArray *pngs = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:nil];
        
        // zip文件路径
        NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
        NSString *zipFilepath = [caches stringByAppendingPathComponent:@"pngs.zip"];
        NSLog(@"zipFilepath = %@",zipFilepath);
        
        // 创建zip文件
        //[SSZipArchive createZipFileAtPath:zipFilepath withFilesAtPaths:pngs];
        [SSZipArchive createZipFileAtPath:zipFilepath withFilesAtPaths:pngs withPassword:@"zkz"];
    }
     //解zip包
    - (IBAction)UnarchiveZipClick:(id)sender {
        NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
        NSString *filepath = [caches stringByAppendingPathComponent:@"pngs.zip"];
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            // 解压(文件大, 会比较耗时,所以放到子线程中解压)
            //[SSZipArchive unzipFileAtPath:filepath toDestination:caches];
            NSError * error;
            [SSZipArchive unzipFileAtPath:filepath toDestination:caches overwrite:YES password:@"zkz" error:&error];
            NSLog(@"error = %@",error);
            NSLog(@"解压完成");
        });
    }
    @end
  • 相关阅读:
    安卓目录分析——MainActivity.java和activity_main.xml
    安卓目录理解 —— AndroidMainifest.xml
    安卓教程列表
    安卓目录介绍
    ideal 安卓环境搭建
    ideal 2019激活 方法
    binding.gyp not found 安装java npm 报错
    vue-cli脚手架打包页面空白
    .java文件转为.class文件转jar包
    前端框架Vue自学之Vue基础语法(二)
  • 原文地址:https://www.cnblogs.com/zkzzkz/p/5258365.html
Copyright © 2011-2022 走看看