Results 1 to 2 of 2
Thread: UTF-8 Encode?
- 02-18-2011, 11:53 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
UTF-8 Encode?
Hi Everyone
I am trying to encode a small string to UTF-8 (JDK 1.5)
Java Code:public void convert() { try { byte[] bytes = "&+&".getBytes("UTF-8"); String harrow = (bytes[0] + " : " + bytes[1] + " : " + bytes[2]); System.out.println(harrow); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } // catch } // convert
But all I get is the ASCII codes for '&+&' ->
38 : 43 : 38
I need the UTF-8 codes, can someone point out what I am doing wrong?
Cheers :)
FR
- 02-18-2011, 07:38 PM #2
Member
- Join Date
- Dec 2010
- Posts
- 57
- Rep Power
- 0
You have to use this code for UTF-8
public void convert() {
try {
String str=new String("&+&","UTF-8");
javax.swing.JOptionPane.showMessageDialog(null,str );
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
} // catch
} // convert
but one thing you should note that utf-8 cod can not show in console...!!!!!!!!
Similar Threads
-
Encode Image into Base64 value.
By onlyabhinav in forum New To JavaReplies: 3Last Post: 01-25-2011, 07:44 AM -
Encode data to torrent?
By greatmajestics in forum AWT / SwingReplies: 0Last Post: 04-28-2010, 04:12 PM -
How to encode a fileHandler to output french characters ?
By l.najm@acteos.com in forum Advanced JavaReplies: 4Last Post: 04-22-2010, 09:21 AM -
Url Encode
By Sean_J in forum New To JavaReplies: 0Last Post: 03-19-2010, 02:54 PM -
Getting problem in UTF-8 Encode/Decode with Java
By sagarsway in forum Advanced JavaReplies: 2Last Post: 12-22-2008, 07:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks