前端之家收集整理的这篇文章主要介绍了
Swift对文件的简单读写操作,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
let file = "file.txt"
if let dirs : [String] = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory,NSSearchPathDomainMask.AllDomainsMask,true) as? [String] {
let dir = dirs[0]
let path = dir.stringByAppendingPathComponent(file);
let text = "some text"
text.writeToFile(path,atomically: false,encoding: NSUTF8StringEncoding,error: nil);
let text2 = String(contentsOfFile: path,error: nil)
}
原文链接:https://www.f2er.com/swift/327282.html