我必须从.bin文件中读取数据。但是我没有找到任何文件或其他东西
我有一个bin文件,我将其复制到项目文件夹中。
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
//setSettings()
let fileName = "MLM_FW_Ver1.3.4.bin"
var filePath = ""
// Fine documents directory on device
let dirs : [String] = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.allDomainsMask, true)
if dirs.count > 0 {
let dir = dirs[0] //documents directory
filePath = dir.appending("/" + fileName)
print("Local path = \(filePath)")
} else {
print("Could not find local directory to store file")
return
}
// Read file content. Example in Swift
do {
let contentFromFile = try NSString(contentsOfFile: filePath, encoding: String.Encoding.utf8.rawValue)
print(contentFromFile)
}
catch let error as NSError {
print("An error took place: \(error)")
}
}
构建该项目并运行代码,然后我看到此错误;
Code = 260“由于没有这样的文件,因此无法打开文件“ MLM_FW_Ver1.3.4.bin”。” UserInfo = {NSFilePath = / var / mobile / Containers / Data / Application / DB021CBC-E3A9-4403-A360-1736ED4A691B / Documents / MLM_FW_Ver1.3.4.bin,NSUnderlyingError = 0x282e82100 {Error Domain = NSPOSIXErrorDomain Code = 2“没有此类文件或目录“}}