文件的压缩和解压

2016-10-02  本文已影响57人  Mario_ZJ

1)说明

1.使用ZipArchive来压缩和解压缩文件需要添加依赖库(libz),使用时需要包含SSZipArchive文件(#import "SSZipArchive.h")
3.如果使用cocoaPoads来安装框架,那么会自动的配置框架的使用环境

  1. 导入依赖库libz

3)相关代码

        /*
         第一个参数:压缩文件要保存的位置
         第二个参数:要压缩哪几个文件
         */
        [SSZipArchive createZipFileAtPath:fullpath withFilesAtPaths:arrayM];
-(void)zip1
{
    NSArray *arrayM = @[
                        @"/Users/apple/Desktop/Snip20160409_139.png",
                        @"/Users/apple/Desktop/Snip20160409_131.png"
                        ];
    
    /*
     第一个参数:压缩文件的目标路径
     第二个参数:要压缩文件的路径(数组)
     */
    [SSZipArchive createZipFileAtPath:@"/Users/apple/Desktop/xmg.zip" withFilesAtPaths:arrayM];
}
        /*
         第一个参数:文件压缩到哪个地方
         第二个参数:要压缩文件的全路径
         */
        [SSZipArchive createZipFileAtPath:fullpath withContentsOfDirectory:zipFile];
-(void)zip2
{
    //压缩根据指定路径中的文件的内容
    [SSZipArchive createZipFileAtPath:@"/Users/apple/Desktop/niuniu.zip" withContentsOfDirectory:@"/Users/apple/Desktop/test"];
}
        /*
         第一个参数:要解压的文件
         第二个参数:要解压到什么地方
         */
        [SSZipArchive unzipFileAtPath:unZipFile toDestination:fullpath];
-(void)unzip
{
    /*
     第一个参数:要解压的文件在哪里
     第二个参数:目的地
     */
    [SSZipArchive unzipFileAtPath:@"/Users/apple/Desktop/niuniu.zip" toDestination:@"/Users/apple/Desktop/liuliu"];
}
上一篇 下一篇

猜你喜欢

热点阅读