【发布时间】:2011-06-13 19:56:58
【问题描述】:
我有以下代码:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"txt"];
if([fileManager fileExistsAtPath:path1]) {
NSLog(@"-- sample file found --");
AccessQuestionsDB *accessQuestionDataFunction = [AccessQuestionsDB new];
idCounter = [accessQuestionDataFunction populateTheDatabase: path1 theID:0 firstTime: YES];
[accessQuestionDataFunction release];
[fileManager removeItemAtPath:path1 error:NULL];
if ([fileManager fileExistsAtPath:path1]) {
NSLog (@"Remove %@ successful", path1);
} else {
NSLog (@"Remove %@ failed", path1);
}
}
else {
NSLog(@"-- NO SAMPLE FILE! --");
}
输出:
2011-06-13 21:41:04.471 xxxx[1726:707] Remove /var/mobile/Applications/B1CC3E09-2A1D-4CD7-976D-E190A238EC79/xxxx.app/myFile.txt successful
当我运行程序时,它表明文件已被删除,见上文,但事实并非如此。当我检查时,使用“iPhone Explorer”文件仍然驻留在“xxxx.app”目录中,我猜这是应用程序的根目录。
如果有好心人能告诉我如何在我需要删除此文件时真正删除它,我将不胜感激。
【问题讨论】:
标签: iphone objective-c nsfilemanager