2013-04-29 67 views
0

在我的應用程序中,我試圖獲取文件的內容,該文件的擴展名是.txt和文件在應用程序中。我想下面提取文件內容問題

path = [[NSBundle mainBundle] pathForResource:@"Last" 
             ofType:@"txt"]; 

content = [NSString stringWithContentsOfFile:path 
            encoding:NSUTF8StringEncoding 
             error:NULL]; 

lines = [content componentsSeparatedByString:@"\n"]; 
NSLog(@"Content Length: %i", [lines count]); 
NSLog(@"%@ %@",content,path); 

但內容和路徑打印null。任何機構知道最新的錯誤嗎?

謝謝。

+1

檢查Last.txt是否包含在您的項目! ? – 2013-04-29 13:01:31

回答

0

我的猜測是Last.txt不在項目中,要在Project Navigator中單擊您的項目(頂級項目),請轉到Build Phases,並檢查該文件是否位於「Copy Bundle Resources」