我有一个应用程序内购买的应用程序,当用户购买东西时,将一个 html 文件下载到我的应用程序的文档文件夹中。
现在我必须检查这个 HTML 文件是否存在,如果是,则加载这个 HTML 文件,否则加载我的默认 html 页面。
我该怎么做?使用 NSFileManager
我无法离开 mainBundle
..
最佳答案
swift 3:
let documentsURL = try! FileManager().url(for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true)
... 为您提供文档目录的文件 URL。以下检查是否有名为 foo.html 的文件:
let fooURL = documentsURL.appendingPathComponent("foo.html")
let fileExists = FileManager().fileExists(atPath: fooURL.path)
objective-C :
NSString* documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString* foofile = [documentsPath stringByAppendingPathComponent:@"foo.html"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];
关于ios - 如何检查文档文件夹中是否存在文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1638834/