aspose file tools*
The moose likes Java in General and the fly likes Java program generates html output with question mark symbols after < anchor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java program generates html output with question mark symbols after < anchor " Watch "Java program generates html output with question mark symbols after < anchor " New topic
Author

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

Marc Christopher
Greenhorn

Joined: Apr 23, 2011
Posts: 2
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

Joined: Sep 07, 2004
Posts: 781

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.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
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>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java program generates html output with question mark symbols after < anchor