【问题标题】:NSFileManager - fileExistsAtPath:?NSFileManager - fileExistsAtPath:?
【发布时间】:2014-12-13 14:28:34
【问题描述】:

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

【问题讨论】:

    标签: nsurl nsfilemanager


    【解决方案1】:

    变化:

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

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

    【讨论】:

      猜你喜欢
      • 2011-04-05
      • 2013-03-17
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      • 2011-04-29
      • 2015-11-30
      • 2023-03-28
      • 2011-01-28
      相关资源
      最近更新 更多