• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

unicode problem in htmleditorkit

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My program use StringWriter to get the unicode in a HTMLEditorKit by this code:
Writer textOut = new StringWriter();
htmlEditorkit.write(str, doc, start, end);
The string I got from this method is in the format of decimal unicode(e.g. 雅). Actually, I do not mind that it is in this format.However, I need to save this string into a file with the format of UTF-8. I have tried to use the following codes:
FileOutputStream fos = new FileOutputStream(new File(fileName));
BufferedWriter out = new BufferedWriter(new outputStreamWriter(fos,"UTF-8"));
out.write(str);
...
However, the content in the file saved is still in the format of
decimal unicode.
How can I get the file with the content in the UTF-8? Thanks!

 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is "decimal unicode"? How does it differ from normal Unicode? How was the string created, anyway? Your code shows a StringWriter called textOut which is never used, and something called str which appears from nowhere. This won't compile as it is - how are these variables actually used in your code?
 
Stephen Lee
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
decimal unicode is a another format of unicode, e.g. '&#xxxxx', while the hexadecimal unicode seems to be more common, e.g. '\uxxxx'.
actually, i don't know why decimal unicode are produced.
sorry that I made a mistake in my first post, it should be
Writer str = new StringWriter();
thx!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic