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;

  • 相关阅读:
    几种简单的博弈 1
    Luogu P2789 直线交点数
    搜索题简记
    并查集的妙用
    [qbzt寒假]线段树和树状数组
    [qbzt寒假]hash
    [qbzt寒假]Trie字典树
    博客阅读须知
    洛谷P1842 [USACO05NOV]奶牛玩杂技——题解
    2020SDOI游记
  • 原文地址:https://www.cnblogs.com/wcLT/p/4678554.html
Copyright © 2011-2022 走看看