stringwriter

Write chinese characters from one file to another

倾然丶 夕夏残阳落幕 提交于 2019-12-02 04:44:56
I have a file with Chinese characters text inside, I want to copy those text over to another file. But the file output messes with the chinese characters. Notice that in my code I am using "UTF8" as my encoding already: BufferedReader br = new BufferedReader(new FileReader(inputXml)); StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append("\n"); line = br.readLine(); } String everythingUpdate = sb.toString(); Writer out = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(outputXml), "UTF8")); out.write(""); out.write

Render partial view to string MVC4

♀尐吖头ヾ 提交于 2019-11-30 14:29:33
I am using the following to render a partial view to a string... protected string RenderPartialViewToString(string viewName, object model) { if (string.IsNullOrEmpty(viewName)) viewName = ControllerContext.RouteData.GetRequiredString("action"); ViewData.Model = model; using (var sw = new StringWriter()) { ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName); var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw); viewResult.View.Render(viewContext, sw); return sw.GetStringBuilder().ToString(); } } However it

Will not closing a stringwriter cause a leak?

巧了我就是萌 提交于 2019-11-30 07:18:55
问题 I realize that in java the GC will eventually cleanup objects, but I'm asking if it is bad practice to not close your string writer, currently I am doing this: private static String processTemplate(final Template template, final Map root) { StringWriter writer = new StringWriter(); try { template.process(root, writer); } catch (TemplateException e) { logger.error(e.getMessage()); } catch (IOException e) { logger.error(e.getMessage()); } finally { } return writer.toString(); } Should I be

Render partial view to string MVC4

ぃ、小莉子 提交于 2019-11-29 21:16:32
问题 I am using the following to render a partial view to a string... protected string RenderPartialViewToString(string viewName, object model) { if (string.IsNullOrEmpty(viewName)) viewName = ControllerContext.RouteData.GetRequiredString("action"); ViewData.Model = model; using (var sw = new StringWriter()) { ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName); var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);

Will not closing a stringwriter cause a leak?

拟墨画扇 提交于 2019-11-29 02:51:14
I realize that in java the GC will eventually cleanup objects, but I'm asking if it is bad practice to not close your string writer, currently I am doing this: private static String processTemplate(final Template template, final Map root) { StringWriter writer = new StringWriter(); try { template.process(root, writer); } catch (TemplateException e) { logger.error(e.getMessage()); } catch (IOException e) { logger.error(e.getMessage()); } finally { } return writer.toString(); } Should I be closing the writer and creating a new String like this: String result = ""; ... finally { result = writer

StringWriter or StringBuilder

放肆的年华 提交于 2019-11-28 04:37:15
What is the difference between StringWriter and StringBuilder and when should I use one or the other? I don't think any of the existing answers really answer the question. The actual relationship between the two classes is an example of the adaptor pattern . StringWriter implements all its Write... methods by forwarding on to an instance of StringBuilder that it stores in a field. This is not merely an internal detail, because StringWriter has a public method GetStringBuilder that returns the internal string builder, and also a constructor that allows you to pass in an existing StringBuilder .

StringWriter or StringBuilder

孤人 提交于 2019-11-27 00:33:20
问题 What is the difference between StringWriter and StringBuilder and when should I use one or the other? 回答1: I don't think any of the existing answers really answer the question. The actual relationship between the two classes is an example of the adaptor pattern. StringWriter implements all its Write... methods by forwarding on to an instance of StringBuilder that it stores in a field. This is not merely an internal detail, because StringWriter has a public method GetStringBuilder that returns