iphone - fileExistsAtPath API 始终返回 NO

标签 iphone objective-c cocoa-touch cocoa

以下是我的代码,我需要检查文档目录中是否存在文件,但是以下 API 在任何情况下都不会返回 true,而是在文档目录中创建文件。请检查我做错了什么。我已经搜索过这个,其他人说这个 API“fileExistsAtPath”应该可以工作,但它在我的情况下不起作用。请帮帮我。

NSString *recordFile=[NSString stringWithFormat:@"MyFile.acc",data.uid];

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                          NSUserDomainMask, YES);
NSString *documentDr = [documentPaths objectAtIndex:0];     // WHY 0 ?
NSString *uniquePath = [documentDr stringByAppendingPathComponent:recordFile];

if([[NSFileManager defaultManager] fileExistsAtPath: uniquePath])
{

    NSLog(@"File found")

}
else {
    NSLog(@"No File to play");
}

谢谢, 索尼

最佳答案

可能你的路径不正确。您要查找的文件的名称应该是什么?如果您有 @"MyFile1.acc"@"MyFile2.acc" 等(其中 1、2 是 data.uid 值)然后尝试使用这个:

NSString *recordFile=[NSString stringWithFormat:@"MyFile%i.acc",data.uid];

关于iphone - fileExistsAtPath API 始终返回 NO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6575446/

相关文章:

ios - 如何找到 NSMutableArray 的最小和最大对象

iphone - 应用播放背景音频不起作用

iphone - 如何在tableview底部添加加载更多按钮?

ios - 致命异常 NSRangeException -[__NSCFString replaceOccurrencesOfString :withString:options:range:]: Range {N, N} 越界;字符串长度 N

iphone - 推送通知进入时的警报序列

iphone - 如何将 nsstring 转换为 cString?

iphone - "The binary you uploaded was invalid. the file was not a valid zip file"将应用程序上传到 iTunes Connect 时出现错误消息

iphone - 为 iCloud 改造我的应用程序

iphone - UIView 不尊重 UINavigationController 中 'loadView' 中的框架

iphone - 构建失败 : symbol(s) not found