//獲得本應用程序的沙盒目錄
NSArray *array=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path=[array objectAtIndex:0];
NSLog(@"%@",path);
//每個應用程序都有自己的沙盒目錄,應用程序之間不能夠相互訪問沙盒目錄
//沙盒目錄下具有Documents,Libray,temp
//Documents目錄下的文件會在itunes備份和恢復時一起備份到服務器和恢復到手機,程序中自己創建的文件需要放到Documents目錄下
//Libray存放的是系統的系統庫,應用程序不能使用Libray目錄
//tmp目錄存放臨時文件,當從新啟動時,會刪除tmp目錄下所有文件
NSDictionary *dict=[[NSDictionary alloc]initWithObjectsAndKeys:@"a",@"b", nil];
NSString *sandBoxPathFile=[NSString stringWithFormat:@"%@/abc.plist",path];
//向本應用程序的沙盒目錄的Documents文件下寫入abc.plist
[dict writeToFile:sandBoxPathFile atomically:YES];
//讀文件
NSDictionary *readDict=[[NSDictionary alloc]initWithContentsOfFile:sandBoxPathFile];
NSLog(@"%@",readDict);
新聞熱點
疑難解答