Iphone development, file path generated by the simulator

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.