Last active
July 15, 2017 16:28
-
-
Save hcn1519/05f6088279331452fedffdf0742c0f62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let fileManager = FileManager() | |
let documentsDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first! | |
let dataPath = documentsDirectory.appendingPathComponent("FileManager Directory") | |
do { | |
try fileManager.createDirectory(atPath: dataPath.path, withIntermediateDirectories: false, attributes: nil) | |
} catch let error as NSError { | |
print("Error creating directory: \(error.localizedDescription)") | |
} | |
do { | |
let helloPath = dataPath.appendingPathComponent("Hello.txt") | |
let text = "Hello File From Swift" | |
do { | |
try text.write(to: helloPath, atomically: false, encoding: .utf8) | |
} | |
} catch let error as NSError { | |
print("Error creating File : \(error.localizedDescription)") | |
} | |
do { | |
let helloPath = dataPath.appendingPathComponent("Hello.txt") | |
let text2 = try String(contentsOf: helloPath, encoding: .utf8) | |
print(text2) | |
} | |
catch let error as NSError { | |
print("Error creating File : \(error.localizedDescription)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment