我試圖檢索到NSString的csv文件的內容。這就是我所做的:CSV到NSString結果爲空的空對象
NSString *strBundle = [[NSBundle mainBundle] pathForResource:@"socs" ofType:@"csv"];
NSLog(@"bundle path: %@",strBundle);
NSString *file = [NSString stringWithContentsOfFile:strBundle
encoding:NSUTF8StringEncoding
error:nil];
if ([[NSFileManager defaultManager]fileExistsAtPath:strBundle]) {
NSLog(@"file is there!!!");
}else {
NSLog(@"no file");
}
NSLog(@"file: %@",file);
NSArray *allLines = [file componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
NSLog(@"lines: %lu",(unsigned long)[allLines count]);
文件管理器顯示該文件在那裏。當我嘗試記錄NSString或文件數量時,它會顯示爲空。我甚至創建了NSData對象,其內容完全相同,當我記錄NSData對象時,我清楚地看到有一些數據。然後,當我嘗試創建帶有NSData內容的NSString時,我的結果與之前一樣 - null。也許問題出在格式化文件的某個地方?
任何幫助將不勝感激:)
您的CSV文件有多大? – random
你認爲你選擇忽略的錯誤信息是什麼? –