NSFileManager - fileExistsAtPath:?

时间:2014-10-17 23:08:45

标签: nsurl nsfilemanager

我试图了解如何使用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!");

1 个答案:

答案 0 :(得分:3)

变化:

NSString *readPath = [[NSURL fileURLWithPath:[self.pathToRead stringValue]] absoluteString];

NSString *readPath = [[NSURL fileURLWithPath:[self.pathToRead stringValue]] path];