File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java program generates html output with question mark symbols after < anchor

 
Marc Christopher
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The output appears as
<�META HTTP-EQUIV=Content-Type CONTENT=text/html; charset=ISO-2022-JP><�HTML><�BODY><�TABLE BORDER=0 CELLPADDING=3 CELLSPACING=1 WIDTH=100%><�TR COLS=2><�TD WIDTH=94% BGCOLOR=WHITE><�FONT FACE=VERDANA COLOR=NAVY SIZE=4><�B>

I have tried setting the mime type
I have tried using character encoding

Neither way works. The source is as follows:



Thanks for any help you can give
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your output suggest that you are expecting to write the HTML using charset=ISO-2022-JP but DataOutputStream.writeChars() just writes each char as two bytes (high byte then low byte) so is equivalent to utf-16 big endian. Rather than use a DataOutputStream you should use an OutputStreamWriter specifying ISO2022JP encoding.
 
Ralph Cook
Ranch Hand
Posts: 479
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We need to know a little bit more about what you're doing.

You're using DataOutputStream, which is going to write java primitives; your characters will all then be written in Unicode, two bytes per character, and I don't know if that's what you want or not.

I don't know what you're using to display the output you've shown us; when I run this, I don't get the same thing. But I'm running on a computer and with programs that expect 8-bit characters. If I change "writeChars" to "writeUTF", I get something more readable, but I don't get anything strange after each left angle bracket.

The other thing I've noticed is that none of the attribute values in your HTML have quotes around them -- assuming you want a browser to display this, you're going to need that -- <table BORDER="0" etc.

rc>
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic