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>