溫故知新,理一遍文件夾路徑
每個APP沙盒下有四個文件夾:documents,tmp,app,Library(裏面還有兩個文件夾Caches 和 Preferences)。
一:作用
1.documents:這是文檔目錄。有關應用的所有數據文件應該寫入到這個目錄下,這個目錄用於存儲用戶數據或者其他應該定期備份的信息。iTunes會同步此文件內容,適合存儲一些重要的數據.
2.tmp:臨時目錄。這個目錄用於存放臨時文件,保存應用程序再次啓動過程中不再需要的信息。
3.app:APP的程序包目錄,可讀,不可操作。
4.Library:庫目錄。
a.Preferences:包含應用程序的偏好設置文件。存放NSUserDefaults保存的.plist文件。iTunes同步該應用時會同步該文件夾中的內容。
b.Caches:緩存目錄。用於存儲應用程序專用的支持文件,保存應用程序再次啓動過程中需要的信息。ITunes不會同步此文件夾,保存一些不需要備份的數據。
二:各文件夾的獲取方法:
1.documents:
NSString *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
2.tmp:
NSString *tmpPath = NSTemporaryDirectory();
3.app:
NSString *path = [[NSBundle mainBundle] bundlePath];
獲取其中的資源: NSString *path = [[NSBundle mainBundle] pathForResource:@"" ofType:@""];
4.Librarys:
/Cache:
NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject;
另外:
Library/Application Support目錄路徑方法:
[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0];
沙盒主目錄路徑 : NSString *homePaht = NSHomeDirectory();