I am trying to read data.txt file with the help of playground. But it is returning nil.
First I instantiated NSFileManager
object. Than used the function fileExistsAtPath
it is returning true.
After instantiating NSFileHandle
it is returning nil.
//: Playground - noun: a place where people can play
import UIKit
var defaultManager = NSFileManager.defaultManager()
if defaultManager.fileExistsAtPath("/Users/toshishakhand/Documents/data.txt") {
print("File exists") // output : File Exists
} else {
print("File not found")
}
var fileHandler: NSFileHandle ? = NSFileHandle(forReadingAtPath: "/Users/toshishakhand/Documents/data.txt")
if fileHandler == nil {
print("File open failed") //output : nil
} else {
print("File does not exist")
}