我使用下面的代码来检查文件是否存在
bool b=[[NSFileManager defaultManager] fileExistsAtPath:filePath];
这些代码可以在 IOS 上运行。
但是当我将它迁移到 mac os x 时,
但我通过filePath发现该文件是否存在于磁盘上,
b 总是返回 0,这意味着该文件不存在。
我想知道ios和macos有区别吗
欢迎任何评论
从文档中,我认为您正在使用路径tilde
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileManager/fileExistsAtPath:isDirectory http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileManager/fileExistsAtPath:isDirectory:
path
文件或目录的路径。如果路径以波形符 (~) 开头,则必须首先使用 stringByExpandingTildeInPath 展开它,否则此方法将返回 NO。
tilde
使路径相对于您的主目录(例如/Users/username/
)
您可以通过致电了解NSLog(@"%@",filePath);
如果 filePath 是 NSString 类型
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)