我有这个树状结构:
Project Folder
build
Project
ProjectTests
Pictures
在子文件夹“项目”中,我有 AppDelegate 和一个名为“Alert.txt”的文件。我想从我的 AppDelegate 访问该文本文件,所以我尝试了:
- (void) applicationDidFinishLaunching:(UIApplication *)application
{
NSLog(@"test");
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath: @"Alert.txt" ] == YES)
NSLog(@"good");
}
当然它会打印“test”,但不会打印“good”。什么是正确的路径?
最佳答案
获取文件路径
NSString * myFile = [[NSBundle mainBundle]pathForResource:@"Alert" ofType:@"txt"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath: myFile ])
NSLog(@"good");
关于objective-c - iOS : I can't find my file?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10998865/