2010-03-17 81 views

回答

5

我没有在我面前有一个苹果的权利,但我相信你想要做类似这样:


NSBundle *myBundle = [NSBundle mainBundle]; 
NSString *pathToFile = [myBundle pathForResource:@"MyImage" ofType:@"jpg"]; 
if (pathToFile != nil) { 
    NSLog(@"MyImage.jpg found in the App bundle."); 
} 

请参阅http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html了解更多信息。

+0

对不起,我花了永远接受一个答案! – 2010-04-13 12:50:08

3

您可以查看文件的存在的东西,如:

NSFileManager *fileManager = [NSFileManager defaultManager]; 
if ([fileManager fileExistsAtPath:aPath]) { ... } 

根据你在找什么, “aPath” 可能是这样的:

NSString *aPath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"Sample.txt"]; 

NSString *aPath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"txt"]; 
相关问题