1. What is a file system?
Each app in iOS has its own file system and access rights, which are generally divided into
~/documents/
~/tmp/
~/library/caches/
~/library/preferences/-------Key-value pairs without caring for file paths.
Its path is obtained in the form of
<span style= "color: #999999;" >{ //Get home directory nsstring *path=nshomedirectory (); NSString *docpath=[path stringbyappendingpathcomponent:@ "Documents"]; NSLog (@ "%@", DocPath); Get file directory Nsarray *documentpath=nssearchpathfordirectoriesindomains (Nsdocumentdirectory,nsalldomainsmask, YES ); NSLog (@ "%@", Documentpath[0]); Get Cache directory Nsarray *cachepath=nssearchpathfordirectoriesindomains (nscachesdirectory, Nsalldomainsmask, YES); NSLog (@ "%@", Cachepath[0]); Get temp directory nsstring *temp=nstemporarydirectory (); NSLog (@ "%@", temp);} </span>
plist files can only store content nsstring nsnumber nsdata Nsarray nsdictionary, and their files are stored in XML format
Nsarray stored in documents:
Nsarray *[email protected][@ "name" @ "age" @ "height"]; NSString *path=nshomedirectory (); NSString *docpath=[path stringbyappendingpathcomponent:@ "Documents"]; NSString *filepath=[docpath stringbyappendingpathcomponent:@ "/aa.plist"]; Store the array in the plist file [arr writetofile:filepath atomically:yes]; Read from file path as array nsarray *arr2=[nsarray Arraywithcontentsoffile:filepath];
Nsdictionary stored in the cache:
Nsdictionary *di[email protected]{@ "name": @ "lean", @ "age": @24,@ "height": @172}; Nsarray *dicarr=nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsalldomainsmask, YES); NSLog (@ "%@", Dicarr[0]); NSString *dirpath=dicarr[0]; NSString *filepath=[dirpath stringbyappendingpathcomponent:@ "Dic.plist"]; Store the dictionary in the plist file [dic Writetofile:filepath Atomically:yes]; Read from file path as dictionary nsdictionary *dic2=[nsdictionary Dictionarywithcontentsoffile:filepath];
NSData Reading Pictures:
Reading and writing pictures can be stored directly only through NSData. //The following example stores a file from Uiimageview and reads the display in another control Nsarray *arr=nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsalldomainsmask, YES); NSLog (@ "%@", Arr[0]); NSString *cachepath=arr[0]; NSString *filepath=[cachepath stringbyappendingpathcomponent:@ "Image.plist"]; UIImage *IMAGE=[SELF.A image]; NSData *data=uiimagejpegrepresentation (image,1); [Data Writetofile:filepath Atomically:yes]; NSData *data2=[nsdata Datawithcontentsoffile:filepath]; UIImage *image2=[uiimage Imagewithdata:data2]; Self.b.image=image2;