Two Laptop Bag*
The moose likes Java in General and the fly likes utf-8 encoding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

utf-8 encoding

bryan lim
Ranch Hand

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

i want to encode my file in utf-8 format. below is my code snippet:


however, when i open my file using notepad++ ......it shows encoding of ANSI...... how can i encode sucessfully? i also tried "UTF8" .......

thanks!!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
The string "testing" contains only characters that are identical in ASCII, ANSI and UTF-8, so the editor has no way of knowing which encoding is used.

It's also possible that the editor bases its decision of whether or not UTF-8 is used on the presence or absence of a BOM (which your code does not write).


Ping & DNS - my free Android networking tools app
Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
refer this example


You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65

That example is actually worse than bryan's code because it uses an incorrect encoding name ("UTF8"). It's also only a partial solution because it punts on the issue of BOMs.
bryan lim
Ranch Hand

Joined: Dec 26, 2008
Posts: 140
so do you mean that the file is already in utf-8 format?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
As I said, the string "testing" is identical in both encodings, so there's no way for the editor to tell the difference, barring a BOM.

I think you should read up on what UTF-8 really means, and how it does and does not differ from ASCII/ANSI. The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) is a good introduction.
bryan lim
Ranch Hand

Joined: Dec 26, 2008
Posts: 140
i see. thank you and i just read it. and i tested it again with a proper soap string. it works.
bryan lim
Ranch Hand

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

I am still having some problem with the encoding.

my xml file has a  at the front.

after googling abit, i realised it is BOM. But my code is below and doesn't include any BOM.



can someone advise me how to get the encoding right? i just want to send this xml file as a soap message. thanks!
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

I'm a bit confused by your line:

String content ="/*supposed a soap message */;

It's not valid Java... What is the actual content you're putting into the SOAP message?

Also are you seeing the BOM before or after your transport via SOAP?

Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: utf-8 encoding