- (NSString *)SaveFileToDocuments:(NSString *)url { // NSString *url = @"http://172.28.250.70/ad/20140210151602.jpg"; NSString *FileName = [url lastPathComponent]; NSString *resultFilePath = @""; if (url.length > 7) { NSString *destFolderPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"IadImages"]; NSString *destFilePath = [destFolderPath stringByAppendingPathComponent:url]; if (! [[NSFileManager defaultManager] fileExistsAtPath:destFolderPath]) { //判断文件夹是否存在 [[NSFileManagerdefaultManager] createDirectoryAtPath:destFolderPath withIntermediateDirectories:YESattributes:nilerror:nil]; } if ([[NSFileManager defaultManager] fileExistsAtPath:destFilePath]) { //判断文件是否存在 resultFilePath = destFilePath; } else { NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]]; if ([imageData writeToFile:destFilePath atomically:YES]) { resultFilePath = destFilePath; } else { resultFilePath = destFilePath; } } } return resultFilePath; } - (NSString*)UTF8_To_GB2312:(NSString*)utf8string { NSStringEncoding encoding =CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); NSData* gb2312data = [utf8string dataUsingEncoding:encoding]; return [[NSString alloc] initWithData:gb2312data encoding:encoding]; }
时间: 2024-11-07 20:34:00