[jdom-interest] saving UTF-8 encoded XML

Jason Novotny novotny at aei.mpg.de
Fri Apr 30 12:14:45 PDT 2004


    I found the completely non-obvious answer from the Java 
internationalization FAQ at

http://www.i18nfaq.com/java.html#6

    Jason


Jason Novotny wrote:

>
> 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
>
>
>
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com 
>
>




More information about the jdom-interest mailing list