美文网首页
iOS判断Documents资源是否存在

iOS判断Documents资源是否存在

作者: 毛毛虫灾害 | 来源:发表于2016-07-04 10:27 被阅读1275次

检索Documents目录的完整路径的两种方法:

NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);    
NSString *documentsDirectory = [paths objectAtIndex:0];

判断Documents下的某个资源文件是否存在

    NSString  *filename=@"123.mp3";
    NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:filename];
    if(![fileManager fileExistsAtPath:filePath])
    {
        NSLog(@"文件不存在");
    }else{
        NSLog(@"文件存在");
    }

相关文章

网友评论

      本文标题:iOS判断Documents资源是否存在

      本文链接:https://www.haomeiwen.com/subject/whvcjttx.html