Java applet file dialog encoding

Discussion in 'Java' started by maxwelton@my-deja.com, Feb 9, 2006.

  1. Guest

    This problem concerns values returned from a FileDialog.getDirectory
    that appear to be ASCII encoded. I need these to be in UTF-16.
    This problem only seems to occur using the Apple version of the applet.

    My java version is 1.4.2_03
    The problem is not there if I type the name of the directory but only
    if
    I select it.
    If I set the Mac in spanish and select a directory in the file save
    dialog with an accented character > 0x7f, the FileDialog is giving
    me 2 characters instead of one and it isn't UTF-8 or UTF-16.
    For example if the directory name has the character: é , the bytes
    I am getting are 0x65 and "unreadable" which is represented by ? or
    0x3f..
    When I use getBytes(UTF-16) encoding I can read the second one.
    They are 0065 (this is e) and 0301 (this is ' ). It appears to make the

    one character into two. What I want is 00E9 the UTF-16 value.
    Does anyone know what is needed to fix this problem? The file
    actually gets stored in the directory but It is preventing my
    launch from working.
    Here is a snippet::

    String fileDirectory;
    Frame theFrame = new Frame();
    FileDialog myDialog = new FileDialog(theFrame, "Dialog Box",
    FileDialog.SAVE);

    myDialog.show();
    if (myDialog.getDirectory() != NULL){
    fileDirectory = myDialog.getDirectory();

    // debug section //
    byte[] values = fileDirectory.getBytes("UTF-16")
    String hex = "";
    String tmp = "";
    for(int i = 0; i < values.length; i++){
    tmp = Integer.toHexString(values);
    if (tmp.length() == 1){
    hex += '0'+tmp;
    }else{
    hex += tmp;
    }
    }
    System.out.println("Hex values: "+hex);
    }
    , Feb 9, 2006
    #1
    1. Advertising

  2. Guest

    wrote:
    > This problem concerns values returned from a FileDialog.getDirectory
    > that appear to be ASCII encoded. I need these to be in UTF-16.
    > This problem only seems to occur using the Apple version of the applet.
    >
    > My java version is 1.4.2_03
    > The problem is not there if I type the name of the directory but only
    > if
    > I select it.
    > If I set the Mac in spanish and select a directory in the file save
    > dialog with an accented character > 0x7f, the FileDialog is giving
    > me 2 characters instead of one and it isn't UTF-8 or UTF-16.
    > For example if the directory name has the character: é , the bytes
    > I am getting are 0x65 and "unreadable" which is represented by ? or
    > 0x3f..
    > When I use getBytes(UTF-16) encoding I can read the second one.
    > They are 0065 (this is e) and 0301 (this is ' ). It appears to make the
    >
    > one character into two. What I want is 00E9 the UTF-16 value.
    > Does anyone know what is needed to fix this problem? The file
    > actually gets stored in the directory but It is preventing my
    > launch from working.
    > Here is a snippet::
    >
    > String fileDirectory;
    > Frame theFrame = new Frame();
    > FileDialog myDialog = new FileDialog(theFrame, "Dialog Box",
    > FileDialog.SAVE);
    >
    > myDialog.show();
    > if (myDialog.getDirectory() != NULL){
    > fileDirectory = myDialog.getDirectory();
    >
    > // debug section //
    > byte[] values = fileDirectory.getBytes("UTF-16")
    > String hex = "";
    > String tmp = "";
    > for(int i = 0; i < values.length; i++){
    > tmp = Integer.toHexString(values);
    > if (tmp.length() == 1){
    > hex += '0'+tmp;
    > }else{
    > hex += tmp;
    > }
    > }
    > System.out.println("Hex values: "+hex);
    > }



    Anybody?
    , Mar 2, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. webster
    Replies:
    0
    Views:
    851
    webster
    Jul 20, 2003
  2. Krista
    Replies:
    3
    Views:
    2,315
    Andrew Thompson
    Sep 15, 2004
  3. yw
    Replies:
    3
    Views:
    818
    Phlip
    Jul 2, 2005
  4. Matt
    Replies:
    1
    Views:
    278
    Randy Webb
    Nov 20, 2004
  5. Replies:
    2
    Views:
    368
Loading...

Share This Page