iOS企业级开发实用技术iOS Developer

我在沙河路径下遇到的坑

2016-11-29  本文已影响77人  强强刘

开发中有时会遇到,需要往本地沙河路径下写入一些文件或者创建文件夹缓存一些pdf或者word等

NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *directoryPath = [NSHomeDirectory() stringByAppendingPathComponent:@"FileTemp"];
    NSError *error = nil;
    if ([fileManager createDirectoryAtPath:directoryPath withIntermediateDirectories:YES attributes:nil error:&error] != YES) {
        //创建失败
        [fileManager createDirectoryAtPath:directoryPath withIntermediateDirectories:YES attributes:nil error:&error];
    }else {
        //创建成功
    }
NSString *pathDocuments = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
NSString *KPath = [NSString stringWithFormat:@"%@/FileTemp",pathDocuments];
NSFileManager *fileManager = [[NSFileManager alloc]init];
    if (![[NSFileManager defaultManager]fileExistsAtPath:KPath]) {
        
        [fileManager createDirectoryAtPath:KPath withIntermediateDirectories:YES attributes:nil error:nil];
        
    }else{
        NSLog(@"有这个文件了");
    }

ps:如有不足和更高的见解欢迎评论或私信😆

上一篇下一篇

猜你喜欢

热点阅读