2011-12-09 97 views

回答

1

//文件(NSArray的NSDictionary的或)被保存在data.plist文件

- (IBAction爲)saveFile的:(ID)發送{

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                 NSUserDomainMask, YES); 
NSString *documentsDirectoryPath = [paths objectAtIndex:0]; 
NSString *filePath = [documentsDirectoryPath 
         stringByAppendingPathComponent:@"data.plist"]; 
[file writeToFile:filePath atomically: YES]; 

} 
+0

這個代碼的任何想法? (NSString *)dataFilePath { NSArray * path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString * documentsDirectoryPath = [path objectAtIndex:0]; NSArray * filePath = [documentsDirectoryPath stringByAppendingPathComponent:@「myList.plist」]; dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:filePath]; 返回字典; } ' – Albert

+0

NSNumber * number = [NSNumber numberWithInt:3]; [dictionary setObject:number forKey:@「key3」];對於(id鍵在字典中){ ({「key key in dictionary」){NSLog(@「web key =%@,value =%@」,key,[dictionary objectForKey:key]); [dictionary writeToFile:[self dataFilePath] atomically:YES]; – Albert

+0

@ user1049312我的代碼將搜索文檔目錄的路徑,然後將文件名添加到文檔目錄路徑中...將給出文件的路徑...然後在該路徑上寫入文件。 –