Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

[jdom-interest] saving UTF-8 encoded XML

Jason Novotny

2004-04-30

Replies:


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@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.