文件读写 swift

//

// ViewController.swift

// 文件读写

//

// Created by mac on 15/7/12.

// Copyright (c) 2015年 fangyuhao. All rights reserved.

//

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
var sp = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true)
println(sp.count)
if sp.count > 0 {
var url = NSURL(fileURLWithPath: "\(sp[0])/data.txt")
println(url)
var data = NSMutableData()
data.appendData("Hello Swift\n".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)!)

// data.appendData("Hello Swift\n".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)!)

data.writeToURL(url!, atomically: true)

// var data1:NSData = "Hello Holyant\n".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)!

// data1.writeToURL(url!, atomically: true)

var str = NSString(contentsOfURL: url!, encoding: NSUTF8StringEncoding, error: nil)

println(str!)

println("end")

}

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

}

上一篇:css基础知识之属性选择器


下一篇:CSS基础 盒子相关属性总结 padding+border