现在我正在开发一个需要 NSFileManager
的 iOS 应用程序,但是当我执行 attributesOfItemAtPath:
方法时,它返回 null。这在 NSData 和 dataWithContentsOfFile:
方法上也会失败。我不明白为什么会这样。我使用的文件 URL 看起来像这样:file://localhost/private/var/mobile/Applications/597DE145-33D7-4F92-AE95-029D5CF15291/tmp/Kv7DWqtRWH7WnN47HdDW
。我怀疑它可能与网址有关,但我不确定。
最佳答案
您需要将 NSURL
转换为一个路径,以便与任何采用字符串的 NSFileManager
方法一起使用。通过在 URL 上调用 path
方法来完成此操作。
NSURL *someURL = ... // some file URL
NSString *path = [someURL path]; // convert the file:// URL to a file path
NSDictionary *info = [[NSFileManager defaultManager] attributesOfItemAtPath:path];
关于ios - NSFileManager Attributesforitem 失败并返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13391011/