This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes encoding in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "encoding in java" Watch "encoding in java" New topic

encoding in java

bryan lim
Ranch Hand

Joined: Dec 26, 2008
Posts: 140
hi all,

i recently made some changes to my encoding of soap xml file. below is my encoding code: filename is a string that contains the name of a file.... content is a string that contains the soap message.

however, i am getting a few undesirable characters at the beginning of my soap file 


because of those characters, i am having problem with sending the soap xml to the server.

can someone please help me to do a proper utf-8 encoding ? did i do it wrongly?
Christophe Verré

Joined: Nov 24, 2005
Posts: 14687

however, i am getting a few undesirable characters at the beginning of my soap file

What is the content of out.write(content); ? Did you debug it ?

[My Blog]
All roads lead to JavaRanch
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

That looks like a byte-order mark (see also this), which are special bytes to let whatever program that reads the file know if the Unicode characters are stored in little endian or big endian order.

In principle, this should not be a problem, but some software does not properly recognise the BOM and reports an error.

Sorry, I don't know how to prevent the BOM from being generated, but maybe you can find a solution yourself by Googling around about Java, Unicode and BOMs.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
bryan lim
Ranch Hand

Joined: Dec 26, 2008
Posts: 140
thank you for your reply.

the content is [quote<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap=""> <soap:Header> <Authentication xmlns=""> <UserName></UserName> <Password>passwprd</Password> </Authentication> </soap:Header><soap:Body><CreateList xmlns=""><name>_2009_3_31</name><description>_2009_3_31</description></CreateList></soap:Body></soap:Envelope> which i mentioned above....

the first few undesirable characters are 

thank you
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41129
So where is "content" coming from? Java I/O doesn't add the BOM by itself - there must be code somewhere that adds that.

Ping & DNS - my free Android networking tools app
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38040
Too difficult a question for us beginners.
Martijn Verburg

Joined: Jun 24, 2003
Posts: 3274

Locked duplicate thread on this, continuing here.

Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
I agree. Here's the link:
subject: encoding in java
Similar Threads
utf-8 encoding
how to set an attribute like SOAPAction in the Header?
populate data via soap from webservice
problem with perl web services and java client
Simple SOAP client