我正在将文件下载到目的地,我可以确认该文件在那里,实际上我可以检查该文件是只读还是可写,但是当我尝试显示上下文时出现错误这个文件:"Error Domain=NSCocoaErrorDomain Code=257 "The file “Documents” couldn’t be opened because you don’t have permission to view it
。以前有人有过这个问题吗?它让我疯狂,因为我甚至无法追踪我电脑上的位置,因为我正在使用我的iPad运行应用程序。如果有人可以帮助我,将不胜感激。
我检查文件的代码段:
let documentsURL = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let checkValidation = NSFileManager.defaultManager()
if (checkValidation.fileExistsAtPath(documentsURL))
{
print("FILE AVAILABLE");
}
else
{
print("FILE NOT AVAILABLE");
}
print(documentsDirectoryPath)
if checkValidation.isWritableFileAtPath(documentsURL) {
print("File is writable")
} else {
print("File is read-only")
}
var newarray = [Int]()
do{
let data = try String(contentsOfFile: documentsURL as String,
encoding: NSASCIIStringEncoding)
print(data)
print("i am at the do statement")
newarray = data.characters.split(){$0 == ","}.map{
Int(String.init($0).stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()))!}
print(newarray)
}
catch let error {
print(error)
}