//
// 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.
}
}