码迷,mamicode.com
首页 > 移动开发 > 详细

IOS文件下载

时间:2015-07-26 20:43:08      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

 NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask,YES);//使用C函数NSSearchPathForDirectoriesInDomains来获得沙盒中目录的全路径。

    

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

    

    NSString *ourDocumentPath =[documentPaths objectAtIndex:0];

    NSString *sandboxPath = NSHomeDirectory();

//    NSString *documentPath = [sandboxPath  stringByAppendingPathComponent:@"Purchase.app"];//将Documents添加到sandbox路径上//stringByAppendingPathComponent

    NSString *FileName=[ourDocumentPath stringByAppendingPathComponent:_fileName];//fileName就是保存文件的文件名

    

    NSLog(FileName);

    NSFileManager *fileManager = [NSFileManager defaultManager];

    // Copy the database sql file from the resourcepath to the documentpath

    if ([fileManager fileExistsAtPath:FileName])

    {

        return FileName;

    }else

    {

        NSURL *url = [NSURL URLWithString:fileUrl];

        NSData *data = [NSData dataWithContentsOfURL:url];

        [data writeToFile:FileName atomically:YES];//将NSData类型对象data写入文件,文件名为FileName

    }

    return FileName;

IOS文件下载

标签:

原文地址:http://www.cnblogs.com/wcLT/p/4678554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!