//Get file path /** 1 * Bundle is a directory that contains all of the resources of the application, which can be obtained by mainbundle the directory resource*/NSString*filepath = [[NSBundle mainbundle] Pathforresource:@"Contactsinfo"Oftype:nil]; NSLog (@"%@", FilePath); //Take the contents of the file out and store it in a string with the contents of it you can do some of the corresponding operations.NSString *string=[NSString Stringwithcontentsoffile:filepath encoding:nsutf8stringencoding Error:nil]; NSLog (@"%@",string); //Get the sandbox path get this path to find the AskNSString *sandboxpath =nshomedirectory (); NSLog (@"%@", Sandboxpath); /** * There are 3 folders in the sandbox * 1 documents the file data that is established in the program or browsed in the program is stored in this directory * 2 Library stored program default settings or other status information * 3 TMP Storage Pro When file * 4 application Package*/ //Get document Path//Method 1NSString *documentfilepath = [Sandboxpath stringbyappendingstring:@"/document"]; NSLog (@"%@", Documentfilepath); //Method 2NSString *documentfilepath1 = [Sandboxpath stringbyappendingpathcomponent:@"doucment"]; NSLog (@"%@", documentFilePath1); //Method 3NSString *documentfilepath2 = [Nssearchpathfordirectoriesindomains (nsdocumentdirectory, NSUserDomainMask, YES) Objectatindex:0]; NSLog (@"%@", documentFilePath2); //There are three ways to get the Document//writes a string to the specified file a second write overwrites the first writeNSString *afilepath = [DocumentFilePath2 stringbyappendingstring:@"a.txt"]; NSString*str =@"Hello World"; [Str writetofile:afilepath atomically:yes encoding:nsutf8stringencoding Error:nil]; //reads a string from the specified fileNSString *STR2 =[NSString Stringwithcontentsoffile:afilepath encoding:nsutf8stringencoding Error:nil]; NSLog (@"%@", STR2); /** * file writes and reads are conditional nsstring Nsarray nsdictionary NSData These types of data can be written in * * Nsarray nsdictionary NSData In and read out the same way*/
For reference only big God don't squirt