為了獲取NSBundle對象蚕脏,一般會調(diào)用該類的mainBundle方法碍讯,該方法就會返回該應(yīng)用對應(yīng)的應(yīng)用程序包。
-URLForResource:withExtension:subdirctory:根據(jù)資源名,擴(kuò)展名指定子目錄獲取該資源對應(yīng)的URL
...:withExtension:根據(jù)資源名网棍、擴(kuò)展名獲取該資源對應(yīng)的路徑
-pathForResource:ofType:根據(jù)資源名類型名
-URLsForResourcesWithExtensionLsubdirectory:獲取指定目錄下匹配特定的擴(kuò)展名的所有資源對應(yīng)的URL組成的數(shù)組
pathForResource:ofType:inDirectory:從指定子目錄下师骗。根據(jù)資源名历等、類型名獲取該資源對應(yīng)的路徑
-pathForResourcesOfType:inDirectory:獲取指定子目錄下匹配特定類型名的所有資源對應(yīng)的路徑組成的數(shù)組
-resourcePath:種子節(jié)根據(jù)完整資源路徑獲取對應(yīng)資源
NSString* filePath=[[NSBundle mainBundle] pathForResource:@"123" ofType:@"txt"];
NSString* content=[NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@",content);