Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2006

Tip: Looking for answers? Try searching our database.

Java applet file dialog encoding

Thread view: 
maxwelton@my-deja.com - 09 Feb 2006 22:06 GMT
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[i]);
       if (tmp.length() == 1){
             hex += '0'+tmp;
       }else{
              hex += tmp;
       }
   }
System.out.println("Hex values: "+hex);
}
maxwelton@my-deja.com - 02 Mar 2006 23:28 GMT
> This problem concerns values returned from a FileDialog.getDirectory
>  that appear to be ASCII encoded. I need these to be in UTF-16.
[quoted text clipped - 42 lines]
> System.out.println("Hex values: "+hex);
> }

Anybody?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.