Swift對檔案的簡單讀寫操作

來源:互聯網
上載者:User

標籤:swift   ios   

let file = "file.txt" if let dirs : [String] = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true) as? [String] {     let dir = dirs[0] //documents directory     let path = dir.stringByAppendingPathComponent(file);     let text = "some text" //writing    text.writeToFile(path, atomically: false, encoding: NSUTF8StringEncoding, error: nil); //reading     let text2 = String(contentsOfFile: path, encoding: NSUTF8StringEncoding, error: nil) }

Swift對檔案的簡單讀寫操作

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.