2012-06-12 66 views
0

我有这样的树状:iOS:我无法找到我的文件?

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"); 

} 

当然它打印“测试”,而不是“好”。什么是正确的道路?

回答

3

要获取路径到您的文件使用

NSString * myFile = [[NSBundle mainBundle]pathForResource:@"Alert" ofType:@"txt"];  
NSFileManager *fileManager = [NSFileManager defaultManager]; 
if ([fileManager fileExistsAtPath: myFile ]) 
    NSLog(@"good"); 
+0

我猜你的意思'fileExistsAtPath:myFile'。非常感谢 ! – Rob

+0

对不起,欢迎您:)我会更新答案,请求也不要忘记接受答案,如果它是有用的欢呼:) –

+0

我会尽快做到这一点,只要我被允许。 ;) 再次感谢 ! – Rob

1

尝试以下操作:

NSString *path = [[NSBundle mainBundle] pathForResource:@"Alert" ofType:@"txt];

相关问题