[jdom-interest] saving UTF-8 encoded XML

Jason Novotny novotny at aei.mpg.de
Fri Apr 30 11:17:55 PDT 2004


Hi,

    I have a web form that allows a user to edit (using a textarea HTML 
element)  and save a XML descriptor file encoded in UTF-8. For sake of 
argument it looks like this:

<?xml version="1.0" encoding="UTF-8"?>
...
<title lang="cs">Výchozí</title>
...

   
    Now I get the text from the textarea using request.getParameter() 
for instance and I want to save it to a file. I've tried both the 
following but it does not work:

            FileOutputStream out = new FileOutputStream(myFile);
            byte[] text = newText.getBytes("UTF-8");   
            out.write(text);
            out.close();

and then also:

        Writer out = new BufferedWriter(new OutputStreamWriter(new 
FileOutputStream(groupFile), "UTF-8"));
        out.write(newText);
        out.close();

It seems that no matter what the text gets garbled and the accents are 
messed up when I load it in again. Any help is greatly appreciated-- I'm 
sorry if this is not the write list, I was unsure of where to post a 
general question such as this...

    Thanks, Jason







More information about the jdom-interest mailing list