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.
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()).
Another thing I tried was to have the program access an existing file instead of creating a new one:
SAXBuilder builder = new SAXBuilder();
try {
String curEl = new String(currentElement.getAttribute("word").getValue());
Document doc = builder.build("file.txt");
Element incorrect = new Element("entry");
incorrect.setAttribute("word", "curEl");
doc.getRootElement().addContent(incorrect);
Format format = Format.getPrettyFormat
();
format.setEncoding("UTF-8");
try {
XMLOutputter outputter = new XMLOutputter(format);
outputter.output(doc, System.out);
System.out.flush();
}
catch (IOException e2) {
System.err.println(e2);
}
} catch (JDOMException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
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" />
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.
What do you think?
On 5/22/07, Grzegorz Kaczor <grzegorz.kaczor@gmail.com> wrote:
You can write:
(...)
writer.newLine();
writer.write("<title name ='words' />");
writer.newLine();
for (...) {
... wait for user click ...
outputter.output...
}
writer.write
("</word_list>");