Ios file operations, ios files

Source: Internet
Author: User

Ios file operations, ios files

<Span style = "font-size: 14px;"> NSData * condata = responseObject; // sets the encoding format. This encoding format can be used to read NSStringEncoding enc = encode (kCFStringEncodingGB_18030_2000 ); NSString * rcontent = [[NSString alloc] initWithData: condata encoding: enc]; NSLog (@ "suceess % @", rcontent); NSString * filePath = [NSHomeDirectory () stringByAppendingFormat: @ "/Documents/% @", [durl lastPathComponent]; // output file Complete path, including file name NSLog (@ "filepath % @", filePath); NSData * incontent = [rcontent dataUsingEncoding: NSUTF8StringEncoding]; NSLog (@ "ndata % @", incontent ); // determine whether the file exists if ([[NSFileManager defaultManager] fileExistsAtPath: filePath]) {NSLog (@ "yes or no"); // delete the file [[NSFileManager defamanager manager] removeItemAtPath: filePath error: nil]; // you want to write content to the file [[NSFileManager defaultManager] createFileAtPath: filePath contents: incontent Attributes: nil];} // 1. obtain the Documents folder path NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSLog (@ "paths % @", paths ); NSFileManager * fm = [NSFileManager defaultManager]; NSArray * file = [fm subpathsOfDirectoryAtPath: [paths objectAtIndex: 0] error: nil]; NSString * df = [paths objectAtIndex: 0]; // 2. Obtain the NSLog (@ "sd % @", df); if (! Df) {NSLog (@ "not fd");} else {NSLog (@ "fd");} NSString * filenam = [[paths objectAtIndex: 0] stringByAppendingPathComponent: @ "1.txt"]; // The complete path of the Upload File NSLog (@" filennn % @ ", filenam); // check whether the 1.txt file under the documentsfolder exists if ([[NSFileManager defamanager] fileExistsAtPath: filenam]) {NSLog (@ "find");} // read the content of the 1.txt file under the documents folder NSData * read = [NSData dataWithContentsOfFile: filenam]; NSString * ss = [[NSString alloc] initWithData: read encoding: NSUTF8StringEncoding]; NSLog (@ "ss", % @ ", ss); </span>

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.