For objects of an unchangeable type defined by the system, during replication, no new object will be generated. [Ns numb String Array dictionary] R only writes R + Xie read w read-only w + cleans up append a + data persistence after writing a nsuserdefaults only saves the system definition type, it cannot store too much or big data and can be used for system preference settings; plist cannot store Custom Data nskeyedarchiversqlite Database Core dataxml, JSON is simple and easy to transmit // file operation in C Language * fp = fopen ("/users/Apple/desktop/test.txt ", "R +"); If (FP = NULL) {return-1;} Char A [10] = {0}; size_t res = fread (A, 1, 2, FP); If (RES = 0) {printf ("read failed \ n");} printf ("% s \ n", a); fpos_t Pos; fgetpos (FP, & Pos); printf ("POS: % LLD \ n", POS); size_t result = fwrite ("xyzwopq", 1, 6, FP ); fgetpos (FP, & Pos); printf ("POS: % LLD \ n", POS); If (result = 0) {printf ("Write failed \ n");} else {printf ("Write success \ n");} res = fread (A, 1, 2, FP ); if (RES = 0) {printf ("read failed \ n");} printf ("% s \ n", a); fgetpos (FP, & Pos ); printf ("POS: % LLD \ n", POS); fclose (FP); // method of attribute list, only the type defined by the system can be saved nsarray * array1 = [nsarray arraywithcontentsoffile: @ "/users/Apple/desktop/test. plist "]; nslog (@" % @ ", array1); // 1. only types defined by the system can be saved. // 2. too much data or big data nsuserdefaults * userdefault = [nsuserdefaults standarduserdefaults]; // single (real) instance class [userdefault setinteger: 2340 forkey: @ "Age"]; // nsinteger age = [userdefault integerforkey: @ "Age"]; nslog (@ "% d", age); // binary code nsstring * STR = @ "123abc "; nsdata * Data = [STR datausingencoding: nsutf8stringencoding]; nslog (@ "% @", data); // read data from the file data = [nsdata datawithcontentsoffile: @ "/users/Apple/desktop/. out "]; nslog (@" % @ ", data); nsmutabledata * mdata = [nsmutabledata data]; [mdata appenddata: Data]; [mdata appenddata: Data]; // write data in the object [mdata writetofile: @ "/users/Apple/desktop/B. out "atomically: Yes]; nsurl * url = [nsurl urlwithstring: @" http://sqlite.org/images/foreignlogos/nokia.gif "]; nsdata * Nokia = [nsdata datawithcontentsofurl: url]; [Nokia writetofile: @ "/users/Apple/desktop/nokia.gif" atomically: Yes]; // if the system data is not encoded and archived, decoding and re-decoding // @ implementation Dog Two nscoding methods must be implemented-(void) encodewithcoder :( nscoder *) acder {[acder encodeobject: _ name forkey: kdognamekey];} -(ID) initwithcoder :( nscoder *) adecoder {self = [Super init]; If (Self) {self. name = [adecoder decodeobjectforkey: kdognamekey];} return self ;} @ end, // archive and archive nsstring * Str = @ "ABC "; [nskeyedarchiver archiverootobject: Str tofile: @ "/users/Apple/desktop/test. plist "]; nsstring * str1 = [nskeyedunarchiver unarchiveobjectwithfile: @"/users/Apple/desktop/test. plist "]; nslog (@" % @ ", str1); Student * Stu = [[STUDENT alloc] init]; Stu. name = @ "zhangsan"; Stu. age = 30; [nskeyedarchiver archiverootobject: Stu tofile: @ "/users/Apple/desktop/student. plist "]; Student * stu1 = [nskeyedunarchiver unarchiveobjectwithfile: @"/users/Apple/desktop/student. plist "]; nslog (@" % P, % P ", Stu, stu1); nslog (@" % @: % d, % @: % d ", Stu. name, Stu. age, stu1.name, stu1.age); nsdata * studata = [nskeyedarchiver archiveddatawithrootobject: Stu]; [studata writetofile: @ "/users/Apple/desktop/Stu. plist "atomically: Yes]; nsdata * studata2 = [nsdata datawithcontentsoffile: @"/users/Apple/desktop/Stu. plist "]; Student * stu3 = [nskeyedunarchiver unarchiveobjectwithdata: studata2]; nslog (@" % @: % d --- % @: % d ", Stu. name, Stu. age, stu3.name, stu3.age); nsuserdefaults * userdefault = [nsuserdefaults standarduserdefaults]; [userdefault setobject: studata forkey: @ "XXXX"]; nsdata * studata3 = [userdefault objectforkey: @ "XXXX"]; Student * stu4 = [nskeyedunarchiver unarchiveobjectwithdata: studata3]; nslog (@ "% @: % d", stu4.name, stu4.age ); stu4.dog = [[DOG alloc] init]; stu4.dog. name = @ "Xiaoqiang"; [nskeyedarchiver archiverootobject: stu4 tofile: @ "/users/Apple/desktop/dog. plist "]; there are four folders in the sandbox:, Ios. • Documents/tmp/APP/ library • The system provides methods to obtain these directories • nshomedirectory () • nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirecto ry, nsuserdomainmask, yes); • nsstring * docdirectory = [paths objectatindex: 0]; • nstemporarydirectory () • Obtain the path of Chinese source files in the current program • nsstring * ImagePath = [[nsbundle mainbundle] pathforresource: @ "image" oftype: @ "PNG"];, sandbox mechanism, nsstring * home = nshomedirectory (); nslog (@ "% @", home ); nsstring * Doc = [home stringbyappendingpathcomponent: @ "events"]; nslog (@ "% @", DOC); // 2. nsarray * array = nssearchpathfordirectoriesindomains (nscachesdirectory, nsuserdomainmask, yes); nslog (@ "% @", array); nsstring * doc2 = [array firstobject]; nslog (@ "% @", doc2); // 3. TMP nsstring * TMP = nstemporarydirectory (); nslog (@ "% @", TMP); nsstring * name = @ "Camp David Education"; nsstring * Path = [Doc stringbyappendingpathcomponent: @ "test. plist "]; [name writetofile: path atomically: Yes encoding: nsutf8stringencoding error: Nil]; // 4. nsstring * dbpath = [[nsbundle mainbundle] pathforresource: @ "testdb" oftype: @ "DB"]; nslog (@ "% @", dbpath );