2014-10-17 61 views
1

我想了解如何使用NSFileManager,但我有一個文件存在於我的桌面上,當我輸入該文件的路徑時,NSFileManager方法fileExistsAtath:返回False。似乎我失去了一些東西。這是代碼。NSFileManager - fileExistsAtPath:?

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!"); 

回答

3

變化:

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

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