我应该使用应用程序在 iPad 模拟器上下载了一个文件。
如何检查此文件是否存在于 iPad 模拟器文件系统中?
是否有一些文件管理器可用于检查文件的存在及其内容?
我应该使用应用程序在 iPad 模拟器上下载了一个文件。
如何检查此文件是否存在于 iPad 模拟器文件系统中?
是否有一些文件管理器可用于检查文件的存在及其内容?
您可以在以下位置找到模拟器
/用户名/库/应用程序支持/iPhone模拟器/4.2/
其中“4.2”是 SDK 版本。在该文件夹下,您可以在神秘的子文件夹中找到所有应用程序。其中之一是你的。在那里您可以找到“文档”,这是您的应用程序的个人文件夹。
使用这些方法,您可以验证文件目录中是否存在文件。我没有测试过这个确切的例子,但它应该可以工作。
例子:
NSString *filePath = [self dataFilePathInDocuments:@"MyFile.txt"];
if([self fileExistsAtPath:filePath]) {
NSLog(@"The file exits at %@", filePath);
} else {
NSLog(@"The doesn't exist at %@", filePath);
}
代码:
- (NSString *)dataFilePathInDocuments:(NSString*)aFilename {
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDirectory = [paths objectAtIndex:0];
return [docDirectory stringByAppendingPathComponent:aFilename];
}
- (BOOL) fileExistsAtPath:(NSString*)aFilepath {
NSFileManager *fm = [NSFileManager defaultManager];
return [fm fileExistsAtPath:aFilepath];
}