Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java Encoding Problem under Windows vs Linux Platforms

807606Mar 8 2007 — edited Mar 9 2007
Hi All,
I want to encode few characters into UTF-8 under my Java application. For example:
String s = "D��sseldorf";
System.out.println("Test  1: " + new String(s.getBytes(Charset.defaultCharset().name()), "UTF-8"));

System.out.println("Test  11 : " + URLEncoder.encode(new String(new String(s.getBytes(Charset.defaultCharset().name()), "UTF-8"))));
produces (under Windows):
Test 1 : D�sseldorf
Test 11: D%FCsseldorf
which is correct, but when i run the same program under Linux platform, the output comes different, due to a different defaults encoding.
Test 1 : D??sseldorf  //wrong
Test 11 : D%3F%3Fsseldorf   //wrong 
the default encodign under Linux is : US-ASCII, where as under windows: windows-1252, which seems to work.

Now could anybody please tell me the solution to this problem that is the how to solve the encoding problem under the Linux environment?

thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 6 2007
Added on Mar 8 2007
34 comments
2,417 views