-(void)generateCSV
{
NSFileManager *filemgr = [NSFileManager defaultManager];
[filemgr createFileAtPath:@"test.csv" contents:nil attributes: nil];
NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:@"test.csv"];
NSLog (@"why null %@", file);
[file seekToEndOfFile];
NSLog(@"%@", file);
surveyarray = [db retrieveSurvey];
for(int i = -1; i < surveyarray.count; i++)
{
if(i == -1)
{
NSString *str = [NSString stringWithFormat: @"No, CreatedDate, Question1, Question2, Question3, Comment\n"];
[file writeData: [str dataUsingEncoding: NSUTF16LittleEndianStringEncoding]];
}
else
{
survey = [surveyarray objectAtIndex:i];
NSString *str = [NSString stringWithFormat: @"%d, %@, %@, %@, %@, %@\n", i, survey.createddate, survey.question1, survey.question2, survey.question3, survey.comment];
[file writeData: [str dataUsingEncoding: NSUTF16LittleEndianStringEncoding]];
}
}
[file closeFile];
/*CHCSVWriter * csvWriter = [[CHCSVWriter alloc] initWithCSVFile:fullPath atomic:NO];
NSInteger numberOfColumns = 5;
for (NSInteger currentIndex = 0; currentIndex < [surveyarray count]; currentIndex++)
{
id field = [surveyarray objectAtIndex:currentIndex];
[csvWriter writeField:field];
if ((currentIndex % numberOfColumns) == (numberOfColumns - 1))
{
[csvWriter writeLine];
}
}
[csvWriter release];*/
}
ファイルをログに記録して返しました(null)
ログ出力
2012-12-19 14:46:55.853 OCBC[6725:907] (null)
2012-12-19 14:46:55.860 OCBC[6725:907] 2012-12-19 14:14:31
2012-12-19 14:46:55.862 OCBC[6725:907] Interview
2012-12-19 14:46:55.863 OCBC[6725:907] Visitor
2012-12-19 14:46:55.865 OCBC[6725:907] Meet Expectation
2012-12-19 14:46:55.866 OCBC[6725:907] N/A