我正在尝试将我写入控制台的内容镜像到文本文件。这是我编写的代码,但它没有创建 txt 文件。任何帮助是极大的赞赏:
-(NSString *) display
{
NSLog (@" \n ");
NSLog (@"|========== Contents of: %@ =============|", listName);
NSLog (@"|__________________________________________________|");
NSLog (@"| | Song Title | | | Artist | |");
NSLog (@"| ============== | ========== |");
NSLog (@"|~~~~~~~~~~~~~~~~~~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~|");
for ( SongRecord *theRecord in list )
NSLog (@"| %-20s| %-24s |", [theRecord.songname UTF8String],
[theRecord.artist UTF8String]);
NSLog (@"====================================================");
return listing;
}
-(void) saveToFile
{
NSString* fileName = @"Mysongs.txt";
NSString* fullPath = [path stringByAppendingPathComponent:fileName];
[[self display] writeToFile:fullPath atomically:YES encoding:NSUnicodeStringEncoding error:nil];
NSLog (@"The file has been written");
}