Questions tagged [stringwriter]

StringWriter class could refer to java.io.StringWriter (part of the the standard java io library ) or to System.IO.StringWriter (part of .NET framework)

StringWriter class could refer to java.io.StringWriter (part of the the standard java io library ) or to System.IO.StringWriter (part of .NET framework)

76 questions
82
votes
7 answers

StringWriter or StringBuilder

What is the difference between StringWriter and StringBuilder and when should I use one or the other?
MAC
42
votes
4 answers

Will not closing a stringwriter cause a leak?

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) { …
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
14
votes
2 answers

When should I use Java's StringWriter?

What is a Java StringWriter, and when should I use it? I have read the documentation and looked here, but I do not understand when I should use it.
MarkusWillson
  • 411
  • 1
  • 3
  • 11
11
votes
1 answer

Clear all content in XmlTextWriter and StringWriter

I want to clear all of content in XmlTextWriter and StringWriter. Flush() didn't work out. XmlDocument doc = new XmlDocument(); StringWriter sw = new StringWriter(); XmlTextWriter xw = new…
sdeligoz
  • 111
  • 2
  • 6
11
votes
4 answers

Writing to txt file from StringWriter

I have a StringWriter variable, sw, which is populated by a FreeMarker template. Once I have populated the sw, how can I print it to a text file? I have a for loop as follows: for(2 times) { template.process(data, sw); …
user1460557
7
votes
4 answers

"File is being used by another process" after File.Create()

I have an application that creates a text file if the file doesn't already exist and then writes something to it. It works great the first time through, when I am creating and immediately writing to the file. My problem is that the next time this…
Brandon
  • 915
  • 4
  • 23
  • 44
7
votes
2 answers

Render partial view to string MVC4

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 =…
6
votes
1 answer

Return all attributes of an HtmlElement in Web browser

I need to get all of the attributes from my webbrowser.currently,I am using GetAttribute() but this way,I need to know the name of the attributes. Imagine I do not know what is in my webbrowser. My C# code: StringWriter strWriter = new…
Pedram
  • 728
  • 3
  • 10
  • 29
5
votes
3 answers

How to use StringWriter and HtmlWriter together without Code Analysis warnings

I'm using .net and need to get some html text, so I thought I would use the HtmlTextWriter and StringWriter together to get the well-formed html. But despite all the different ways I write the code I still get warnings from the static code analyzer…
Jon Tindel
  • 51
  • 1
  • 3
5
votes
1 answer

Why is DataContractSerializer to StringWriter truncated?

I am using the DataContractSerializer to serialize EF4 objects to xml if there are exceptions. In my debug log i can see want was the data-content when something went wrong. I have two versions of code: one version that serializes to a file and one…
k3b
  • 14,517
  • 7
  • 53
  • 85
5
votes
4 answers

C# Read text file line by line and edit specific line

I want to read a text file line by line and edit a specific line. So, I have put the text file into a string variable like: string textFile = File.ReadAllText(filename); My text file is like: Line A Line B Line C Line abc Line 1 Line 2 Line 3 I…
Giovanni19
  • 135
  • 1
  • 2
  • 7
5
votes
2 answers

Is there a TextWriter child class that fires event if text is written?

I have written a method that accepts a TextWriter as an argument (Usually Console.Out, but not necessarily). When I call this method, some progress info is written to the TextWriter. However, since this method can run a long time, I want to update…
Jürgen Steinblock
  • 30,746
  • 24
  • 119
  • 189
4
votes
2 answers

StringWriter is not disposed along all exception paths

I am working with a StringWriter which I am passing to a method to write values in a foreach loop. I believe this is causing the generation of two warnings: CA2000 : Microsoft.Reliability : In method 'ToCsvService.ToCsv()', object 'sw' is not…
ahsteele
  • 26,243
  • 28
  • 134
  • 248
4
votes
1 answer

Conflict Between StaticWriter and Writer Classes

As of our recent move from WSED 5.2 to RAD 7.5, an application-wrecking bug has appeared in our code. RAD 7.5 marks it thusly, all at the declaration of the class header (public class FoStringWriter extends StringWriter implements FoWriter {) -…
Zibbobz
  • 725
  • 1
  • 15
  • 41
3
votes
5 answers

Java writing a list of strings to a file, but the file is empty

I have found this question in other languages, but have yet to find a solution to this issue in a java application. I have a large .txt file with millions of records. Each record is /n delimited. Basically it is a single column of data from a table.…
Jeremy
  • 326
  • 4
  • 15
1
2 3 4 5 6