I wasn't able to figure out the correct way to use the for statement like you suggested. I tried using the boolean isWanted = true for initialization, isWanted = false for termination, and leaving increment blank, but that didn't work. If you could explain how the proper way to use a for statement in this situation that would help me a lot.
<br><br>I also tried to place an if(listIterator.hasNext()) { statement but depending on where I use it at, it either fails to close the stream and freezes my computer or it won't do anything at all. The same happens with while(
listIterator.hasNext()).<br><br>Another thing I tried was to have the program access an existing file instead of creating a new one:<br><br> SAXBuilder builder = new SAXBuilder();<br> try {
<br> String curEl = new String(currentElement.getAttribute("word").getValue());<br> Document doc = builder.build("file.txt");<br> Element incorrect = new Element("entry");
<br> incorrect.setAttribute("word", "curEl");<br> doc.getRootElement().addContent(incorrect);<br> Format format = Format.getPrettyFormat
();<br> format.setEncoding("UTF-8");<br> try {<br> XMLOutputter outputter = new XMLOutputter(format); <br>
outputter.output(doc, System.out);<br> System.out.flush();<br> }<br> catch (IOException e2) {<br> System.err.println(e2);
<br> }<br> } catch (JDOMException e1) {<br> // TODO Auto-generated catch block<br> e1.printStackTrace();<br> } catch (IOException e1) {
<br> // TODO Auto-generated catch block<br> e1.printStackTrace();<br> }<br><br>This appends the currentElement at the end of the list like I want it to but it still manages to replace the previous element every time. It also puts an unwanted "/" at the end which prevents the program from reading it: <entry word = "word" />
<br><br>I wanted try creating a simple text file and modifying that but I need UTF-8 encoding and I only know how to create a simple txt file with FileWriter, which doesn't allow UTF-8, so I didn't know how to proceed in doing that.
<br><br>What do you think?<br><br><div><span class="gmail_quote">On 5/22/07, <b class="gmail_sendername">Grzegorz Kaczor</b> <<a href="mailto:grzegorz.kaczor@gmail.com">grzegorz.kaczor@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
You can write:<br>(...)<br>writer.newLine();<br>writer.write("<title name ='words' />");<br>writer.newLine();<br>for (...) {<br> ... wait for user click ...<br> outputter.output...<br>}<br>writer.write
("</word_list>");<br></blockquote></div><br>