我试图了解如何使用NSFileManager
,但我的桌面上存在一个文件,当我输入该文件的路径时,NSFileManager方法fileExistsAtath:
返回False。似乎我错过了什么。这是代码。
NSFileManager *fileManager = [NSFileManager defaultManager];
//self.pathToRead is /Users/nikita/Desktop/asdf.wav
NSString *readPath = [[NSURL fileURLWithPath:[self.pathToRead stringValue]] absoluteString];
//readPath is file:///Users/nikita/Desktop/asdf.wav
if(![fileManager fileExistsAtPath:readPath])
NSLog(@"File does not exist!");
答案 0 :(得分:3)
变化:
NSString *readPath = [[NSURL fileURLWithPath:[self.pathToRead stringValue]] absoluteString];
要
NSString *readPath = [[NSURL fileURLWithPath:[self.pathToRead stringValue]] path];