|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Transformer not appending Text
Hi all,
I have the following code which is writing XML to a file but everytime it writes (using Transformer) the message isnt appended but overwrites the information in the file: Code:
// Prepare the DOM document for writing
Source source = new DOMSource(doc);
// Prepare the output file
File file = new File(filename);
Result result = new StreamResult(file);
// Write the DOM document to the file
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(source, result);
Can someone help me so that that when the code runs next time it appends to the existing message rather than overwriting it.... Thanks for any help |
|
#2
|
||||
|
||||
|
Code:
File file = new File(filename); // true indicates that we want to append to the file FileOutputStream os = new FileOutputStream (file, true); Result result = new StreamResult(os); It was the first result that google yielded when I typed in java append file: http://www.javacoffeebreak.com/faq/faq0086.html I then saw that the StreamResult class had a constructor for an OutputStream: http://xml.apache.org/xalan-j/apido...reamResult.html I hope this is the answer you are looking for. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Transformer not appending Text |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|