2010-03-17 84 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"]; 
相關問題