1,獲取家目錄路徑的函數:
NSString*homeDir = NSHomeDirectory();
2,獲取Documents目錄路徑的方法:
NSArray*paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString*docDir = [paths objectAtIndex:0];
3,獲取Caches目錄路徑的方法:
NSArray*paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask,YES);
NSString*cachesDir = [paths objectAtIndex:0];
4,獲取tmp目錄路徑的方法:
NSString*tmpDir = NSTemporaryDirectory();
5,獲取應用程序程序包中資源文件路徑的方法:
例如獲取程序包中一個圖片資源(apple.png)路徑的方法:
NSString*imagePath = [[NSBundle mainBundle] pathForResource:@”apple” ofType:@”png”];
UIImage*appleImage = [[UIImage alloc] initWithContentsOfFile:imagePath];
代碼中的mainBundle類方法用於返回一個代表應用程序包的對象。