你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS學習筆記21—從文本文件中讀取內容到字符串裡

iOS學習筆記21—從文本文件中讀取內容到字符串裡

編輯:IOS開發綜合

 


NSError *error;

NSString *textFileContents = [NSString

stringWithContentsOfFile:[[NSBundle mainBundle]

pathForResource:@”myTextFile”

ofType:@”txt”]

encoding:NSUTF8StringEncoding

error: & error];

// If there are no results, something went wrong

if (textFileContents == nil) {

// an error occurred

NSLog(@”Error reading text file. %@”, [error localizedFailureReason]);

}

NSArray *lines = [textFileContents componentsSeparatedByString:@””];

NSLog(@”Number of lines in the file:%d”, [lines count] );

 


 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved