IOS检测指定路径的文件是否存在

2020-01-14 15:12:49刘景俊

}  

 

检查文件是否存在

 

复制代码
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@""];
if(path==NULL)

 

方法二:

 

复制代码
NSFileManager *fileManager = [NSFileManager defaultManager];
   //Get documents directory
   NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains
   (NSDocumentDirectory, NSUserDomainMask, YES);
   NSString *documentsDirectoryPath = [directoryPaths objectAtIndex:0];
   if ([fileManager fileExistsAtPath:@""]==YES) {
        NSLog(@"File exists");
    }   

 

方法三:

 

复制代码
//判断文件是否存在
    if(![c judgeFileExist:@"user.plist"])       
    {
        NSLog(@"请确认该文件是否存在!");
        return;
    }

 

方法四:

 

复制代码
//判断文件是否存在
-(BOOL)judgeFileExist:(NSString * )fileName
{
    //获取文件路径
    NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@""];
    if(path==NULL)
        return NO;
    returnYES;
}