我使用下面的代码来检查文件是否存在
bool b=[[NSFileManager defaultManager] fileExistsAtPath:filePath];
代码适用于 IOS。
但是当我将它迁移到 mac os x 时,
但是我通过filePath发现文件是否存在于磁盘上, b 总是返回 0,表示文件不存在。
请问ios和macosx有区别吗
欢迎任何评论
最佳答案
从文档中,我认为您正在使用带 波浪号
的路径
路径
The path of a file or directory. If path begins with a tilde (~), it must first be expanded with stringByExpandingTildeInPath, or this method will return NO.
波浪号
使路径相对于您的主目录(例如/Users/username/
)
你可以通过调用 NSLog(@"%@",filePath);
来判断 filePath 是否是 NSString 类型
关于objective-c - 检查文件是否存在 objective-c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7866625/