Data is written locally

Source: Internet
Author: User


Array writes to Local
1. What to write
nsarray* arr = @[@ "1", @ "2", @ "3"];
2. Where to write
NSString *STR2 = [documentstr stringbyappendingpathcomponent:@ "Fuckyou.avi"];
NSLog (@ "%@", documentstr);
3. Write in
[arr writetofile:str2 Atomically:yes];
4. Finish it and get it out.
Nsarray *array = [Nsarray Arraywithcontentsoffile:path];
NSLog (@ "%@", array);


Dictionary writes to Local
Writes directly to the local time after the first write. If you write to the same file again, the previous one is overwritten.
Only one piece of data can be written at a time
If you don't want to overwrite it, read it first and then write it together.
All that can be written directly to the local must comply with the Nscoding protocol
1?? To write something
Nsdictionary *dic = @{@ "Xiao Qiang": @ "silly strong"};
2?? Where to write
NSString *STR3 = [documentstr stringbyappendingstring:@ "/ss.tet"];

3?? Write it in.
[DiC Writetofile:str3 Atomically:yes];
4?? Take it out and try it out.
Nsdictionary *DICC = [Nsdictionary Dictionarywithcontentsoffile:path];
NSLog (@ "document=====%@", documentstr);
NSLog (@ "DICC = = =%@", DICC);


Picture is written locally
NSString *str [email protected] "http://img.fs0757.com/news/2015/0901//2015090110400752.jpg";
Nsurl *url = [Nsurl urlwithstring:str];
NSData *data = [NSData Datawithcontentsofurl:url];
NSString *pathh = [Documentstr stringbyappendingstring:@ "/monkey. png"];
[Data writetofile:pathh Atomically:yes];
Uiimageview *img = [[Uiimageview alloc]initwithframe:cgrectmake (100, 100, 100, 100)];
NSData *data1 = [NSData datawithcontentsoffile:pathh];
UIImage *image = [UIImage imagewithdata:data1];
Img.image = image;
[Self.view addsubview:img];
NSLog (@ "Path = = =%@", path);



Data is written locally

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.