Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing charcters to HTML file result in annoying ending random char 1

Status
Not open for further replies.

thelordoftherings

Programmer
May 16, 2004
616
0
0
IL
Hello,

I need to create an HTML in Java.
In order to do that I create an html file and write the data there using Dataoutputstrem. I am using the writeUTF method since I write hebrew chars. The problem is that every sentence I write ends with a random character which wasn't exist at the original text, it could be ( $ [ ect...
Here is a piece of my code:

FileOutputStream outFile = new FileOutputStream(new File("C:\\Inetpub\\DataOutputStream outData = new DataOutputStream(outFile);
outData.writeBytes("<HTML><HEAD><TITLE> ?? ???????? </TITLE></HEAD><BODY>");
outData.writeBytes("<H1><CENTER>");
outData.writeUTF(" ???? " );
outData.writeBytes("</CENTER></H1><HR><BR><BR>");
outData.writeBytes("<H3>");
outData.writeBytes("<P align=right>");
utData.writeUTF("??? ?????" + "<BR><BR>");
outData.writeBytes("</P></H3><BR>");
outData.writeBytes("</BODY></HTML>");
outData.close();
outFile.close();
 
I would normally use a FileWriter to create the file. Since you want to specify the encoding, the javadoc for the FileWriter recommends :-
JavaDocs said:
Convenience class for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream

Tim
 
Hello tim,

Now when I use FileWriter's write method and put hebrew characters, it writes it as ??? ??? ??? ....
 
Well, like the quote I posted said ... construct an OutputStreamWriter on a FileOutputStream. This should give you the ability, in one of the contructors, to specify the character encoding you need. You'll need to refer to the Api Javadocs for these two classes.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top