獲取一些目錄路徑的方法


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類方法用於返回一個代表應用程序包的對象。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章