iOS creates folders, saves, reads, and deletes files in the document directory

Source: Internet
Author: User

1     //Create a folder named Launchimage in the documents directory2NSString *path = [[Nshomedirectory () stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"Launchimage"];3NSLog (@"%@", path);4     5Nsfilemanager *filemanager =[Nsfilemanager Defaultmanager];6BOOL Isdir =FALSE;7BOOL isdirexist = [FileManager fileexistsatpath:path isdirectory:&Isdir];8     if(! (Isdirexist &&isdir))9         Ten     { OneBOOL Bcreatedir =[FileManager createdirectoryatpath:path withintermediatedirectories:yes attributes:nil Error:nil]; A         if(!Bcreatedir) { -NSLog (@"failed to create folder! "); -         } theNSLog (@"folder created successfully, file path%@", path); -     } -      -UIImage *image=[uiimage Imagewithcontentsoffile:@"Testimage.png"]; +NSData *data =uiimagepngrepresentation (image); -     //Save the Testimage.png to the Launchimage folder with the new name Image1.png +BOOL issaved= [FileManager createfileatpath:[path stringbyappendingstring:@"/image1.png"] Contents:data Attributes:nil]; ANSLog (@"picture Save Status:%d", issaved); at      -     //get a saved picture -UIImage *newimage=[uiimage Imagewithcontentsoffile:[path stringbyappendingstring:@"/image1.png"]]; -     - //Deleting Files -BOOL isdelete=[FileManager Removeitematpath:path error:nil]; inNSLog (@"%d", Isdelete);

iOS creates folders, saves, reads, and deletes files in the document directory

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.