iOS判断Documents资源是否存在

2016-07-04  本文已影响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(@"文件存在");
    }
上一篇 下一篇

猜你喜欢

热点阅读