I'm new to Xcode. I have the following code working perfectly to read a text file located in the project bundle.
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"file开发者_如何学JAVA" ofType:@"txt"];
NSString *textFromFile = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
My question is how to read the text file from URL?
It's a bit more involved than reading a file. Use the NURLConnection
class.
I Found a Way to Read the File By Doing This:
let str = "Text Here"
let filename = getDocumentsDirectory().appendingPathComponent("file.txt")
do {
try str?.write(to: filename, atomically: true, encoding: String.Encoding.utf8)
}catch {
print("Something Went Wrong")
}
精彩评论