2
我使用添加了一个非常简单的.csv文件到我的应用程序的NSDocumentDirectory:在iPad上访问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?
我想补充的答案。此打印输出将显示您的文档在您的Harddrive上的目录。您可以在查找器中打开并查看您的文件。 – MarkPowell
谢谢@MarkPowell,也许我有点简洁:) –
这样做!谢谢! – hemlocker