沙盒中的檔案和檔案夾
1.app(應用程式)包 -》一些程式資源 和二進制程式(執行時不能對包中的檔案進行寫操作)
2.Documents(存放一些自己的檔案)保留存儲一些重要資訊
3.Library -》這個檔案夾下有兩個子檔案夾:Caches 和 Preferences
Preferences 檔案夾:包括應用程式的偏好設定檔案。
用NSUserDefaults類來取得和設定應用程式的偏好設定. Caches 檔案夾:做一些緩存資料。儲存應用程式再次啟動過程中須要的資訊,比方下載下傳圖檔的緩存。
4.tmp 這個檔案夾用于存放暫時檔案。儲存應用程式再次啟動過程中不須要的資訊
1,擷取沙盒家檔案夾路徑的函數: NSString *homeDir = NSHomeDirectory();
2。擷取沙盒Documents檔案夾路徑的方法: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docDir = [paths objectAtIndex:0];
還能夠 NSString * docStr = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
3,擷取Caches檔案夾路徑的方法: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *cachesDir = [paths objectAtIndex:0]; 4。擷取tmp檔案夾路徑的方法: NSString *tmpDir = NSTemporaryDirectory();
5。擷取應用程式程式包中資源檔案路徑的方法: 比如擷取程式包中一個mp3資源(apple.mp3)路徑的方法: NSString *imagePath = [[NSBundle mainBundle] pathForResource:@“apple”ofType:@”mp3”];