【发布时间】:2017-08-11 09:23:32
【问题描述】:
当我使用方法.fileExists(atPath:)判断文件是否存在于文件系统中时,该方法总是返回false给我。我检查了文件系统,文件确实存在。这是我的代码:
let filePath = url?.path
var isDir : ObjCBool = false
if(self.fileManager.fileExists(atPath: filePath!, isDirectory: &isDir)){
let result = NSData(contentsOfFile: filePath!)
}
或
let filePath = url?.path
if(self.fileManager.fileExists(atPath: filePath!)){
let result = NSData(contentsOfFile: filePath!)
}
if 子句总是会被跳过。
【问题讨论】:
-
您是否指向文件所在的确切文件位置??
-
filePath 的值是多少?是以~开头的吗?如果是这样,您首先需要调用扩展的波浪号InPath
-
@user3608500 是的,指向一个确切的文件,我想判断这个文件是否存在。
-
@mlidal 以“/Users/De....”开头
-
可能路径不正确?请检查网址
标签: ios swift nsfilemanager