Finder --- location ---- apple (mac) --- application support --- iphone sinulator --- 4.3 --- Applications -- Simulator --
The following is a ***. app
Documents
Library
Tmp
1. The app root can be accessed using NSHomeDirectory;
2. The Documents directory is where we can write and save files.
Obtaining method:
NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES );
Obtain documents path: NSString * documentsDirectory = [paths objectAtIndex: 0];
3. In the tmp directory, we can write data that is needed when the program is running. The data written in the tmp directory will not exist after the program exits. You can use
NSString * NSTemporaryDirectory (void); method;
Create a directory: for example, to create a test directory under Documents,
Nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes );
Nsstring * documentsdirectory = [paths objectatindex: 0];
Nslog (@ "% @", documentsdirectory );
Nsfilemanager * filemanage = [nsfilemanager defaultmanager];
Nsstring * mydirectory = [documentsdirectory stringbyappendingpathcomponent: @ "test"];
Bool OK = [filemanage createdirectoryatpath: mydirectory attributes: Nil];
Obtain all file names in a directory: (The above mydirectory) Available
Nsarray * file = [filemanager subpathsofdirectoryatpath: mydirectory error: Nil]; or
Nsarray * files = [filemanager subpathsatpath: mydirectory];
Read an object:
Nsdata * Data = [filemanger contentsatpath: myfilepath]; // myfilepath is the file name that contains the complete path
Or directly use the nsdata class method:
Nsdata * Data = [nsdata datawithcontentofpath: myfilepath];
Save an object:
You can use NSFileManager's
-(BOOL) createFileAtPath :( NSString *) path contents :( NSData *) data attributes :( NSDictionary *) attr;
Or NSData
-(BOOL) writeToFile :( NSString *) path atomically :( BOOL) useAuxiliaryFile;
-(BOOL) writeToFile :( NSString *) path options :( NSUInteger) writeOptionsMask error :( NSError **) errorPtr;