18
如何讀取文檔目錄中的.txt文件?你能告訴我代碼嗎?讀取文檔目錄中的.txt文件
如何讀取文檔目錄中的.txt文件?你能告訴我代碼嗎?讀取文檔目錄中的.txt文件
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"txtFile.txt"];
NSString *content = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
您還可以在文件中使用NSFileHandle
寫入數據並保存到文檔目錄: 你可以遵循:NSFileHandle
作爲簡單和容易的片斷是,我會建議增加一些內容或代碼中的註釋 – Sirens