我使用以下方法将一个非常简单的 .csv 文件添加到我的应用程序的 NSDocumentDirectory 中:
-(IBAction)exportModule:(id)sender{
NSString *fileName = @"exportedfile.csv";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *exportString = @"I've,been,exported";
NSData *testData=[exportString dataUsingEncoding:NSUTF8StringEncoding];
NSString *docDir = documentsDirectory;
NSString *completePath = [docDir stringByAppendingPathComponent:fileName];
[testData writeToFile:completePath atomically:YES];
if ([[NSFileManager defaultManager] fileExistsAtPath:completePath]) {
NSLog(@"Theres a file here!");
}
}
该应用程序进入 if 语句打印"Theres a file here!"
,但是我想打开文件并查看格式化 .csv 是否有任何问题。
如果我在物理设备上运行,我可以在 iTunes 中打开它并在那里查看,但是有没有办法只使用模拟器来检查 .csv?