[iOS] 讀寫檔案範例

  • 602
  • 0
  • iOS
  • 2015-06-04

摘要:[iOS] 讀寫檔案範例

[iOS] 讀寫檔案範例

// Document
NSString* documentPath= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

// Write
NSString* writePaht = [documentPath stringByAppendingPathComponent:@"test.txt"];
NSString* writeContent = @"ABCDEFG";
[writeContent writeToFile:writePaht atomically:NO encoding:NSUTF8StringEncoding error:nil];

// Read
NSString* readPath = [documentPath stringByAppendingPathComponent:@"test.txt"];
NSString* readContent = [NSString stringWithContentsOfFile:readPath encoding:NSUTF8StringEncoding error:nil];
期許自己
能以更簡潔的文字與程式碼,傳達出程式設計背後的精神。
真正做到「以形寫神」的境界。