Results 1 to 2 of 2

Thread: UTF-8 Encode?

  1. #1
    FiniteRed is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default 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

  2. #2
    justbeller is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Default

    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

  1. Encode Image into Base64 value.
    By onlyabhinav in forum New To Java
    Replies: 3
    Last Post: 01-25-2011, 07:44 AM
  2. Encode data to torrent?
    By greatmajestics in forum AWT / Swing
    Replies: 0
    Last Post: 04-28-2010, 04:12 PM
  3. How to encode a fileHandler to output french characters ?
    By l.najm@acteos.com in forum Advanced Java
    Replies: 4
    Last Post: 04-22-2010, 09:21 AM
  4. Url Encode
    By Sean_J in forum New To Java
    Replies: 0
    Last Post: 03-19-2010, 02:54 PM
  5. Getting problem in UTF-8 Encode/Decode with Java
    By sagarsway in forum Advanced Java
    Replies: 2
    Last Post: 12-22-2008, 07:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •