zoukankan      html  css  js  c++  java
  • IOS文件下载

     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;

  • 相关阅读:
    hrbust 1840 (树状数组第k大) 删点使用
    20150211--Smarty2-02
    20150211--Smarty2-01
    20150210--Smarty1-02
    20150210--Smarty1-01
    20150209--JS巩固与加强6-02
    20150209--JS巩固与加强6-01
    20150207--JS巩固与加强5
    20150206--JS巩固与加强4-02
    20150206--JS巩固与加强4
  • 原文地址:https://www.cnblogs.com/wcLT/p/4678554.html
Copyright © 2011-2022 走看看