Home arrow static arrow Java Programming [Archive] - help on processing french character with java String class
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - help on processing french character with java String class
This topic has 10 replies on 1 page.

Posts:781
Registered: 5/1/01
help on processing french character with java String class  
Aug 5, 2004 3:49 PM



 
hi all
i have a question about processing french character. i have a file that contains french characters such as �, when it is read in and assigned to a string variable, it becomes ╩, how can i preserver the french characters? thanks
 

Posts:12,831
Registered: 2/22/00
Re: help on processing french character with java String class  
Aug 5, 2004 3:51 PM (reply 1 of 10)



 

How are you reading it in? Are you sure you're using the correct encoding?

How do you know that it wasn't read in correctly? Perhaps it was read in fine but just isn't being displayed right.

How are you displaying it after you've read it in?
 

Posts:781
Registered: 5/1/01
Re: help on processing french character with java String class  
Aug 5, 2004 4:01 PM (reply 2 of 10)



 
thanks for ur response.
i use xml

<Lname>SMIT'H �</Lname>

the file is saved using unicode encoding. and when it is read in, and displayed using system.out.println(), it has been changed to something else. and when i used it in a sql string for insert into database, it is '-' in the database.

 

Posts:27,518
Registered: 11/3/97
Re: help on processing french character with java String class  
Aug 5, 2004 5:12 PM (reply 3 of 10)



 
The following interfaces exist in the above
- The database
- Reading the data from the database
- Writing the data using println.
- Reading data from a file.

You need to identifier exactly what data exists at each interface.

Internally java keeps characters in unicode so you can definitely get that character into unicode. However just because it is in java does not mean that println() is going to display it. Because when println() runs it converts the unicode into a character set (which is determined by the computer, OS, and other factors.)

So the first step is to determine the numeric value of the character in all of the interfaces above. For example it doesn't matter what you do in java if the character in the database is not what you think it is. Or if the driver converts it when it gets read.
 

Posts:781
Registered: 5/1/01
Re: help on processing french character with java String class  
Aug 5, 2004 8:05 PM (reply 4 of 10)



 
The following interfaces exist in the above
- The database
- Reading the data from the database
- Writing the data using println.
- Reading data from a file.

You need to identifier exactly what data exists
at each interface.

the data in xml contains french characters. and i need to store it in the sql server. somehow when it was read in, it was changed to something else.

Internally java keeps characters in unicode so you can
definitely get that character into unicode. However
just because it is in java does not mean that
println() is going to display it. Because when
println() runs it converts the unicode into a
character set (which is determined by the computer,
OS, and other factors.)

So the first step is to determine the numeric value of
the character in all of the interfaces above. For
example it doesn't matter what you do in java if the
character in the database is not what you think it is.
Or if the driver converts it when it gets read.

are u saying that i need to get the numeric value of the character first? how would i save it in the DB?
 

Posts:183
Registered: 5/28/04
Re: help on processing french character with java String class  
Aug 6, 2004 4:45 AM (reply 5 of 10)



 
The following interfaces exist in the above
- The database
- Reading the data from the database
- Writing the data using println.
- Reading data from a file.

Looks like you have been given a thorough recipe to find and fix your problem. You need to check each one of these in order, bottom to top.

The most likely suspect is reading the file. Are you specifiying UTF-8 encoding on your FileInputStream? If not, you will pick up the default encoding from the OS.
InputStreamReader reader = new InputStreamReader(new FileInputStream(xmlFile), "UTF-8");


-Scott
 

Posts:781
Registered: 5/1/01
Re: help on processing french character with java String class  
Aug 6, 2004 5:13 AM (reply 6 of 10)



 
i am using weblogic integration tool to read file. i am not sure if anyone is familiar with it. i suppose i should ask bea how i can set the encoding for reading the file.
 

Posts:27,518
Registered: 11/3/97
Re: help on processing french character with java String class  
Aug 6, 2004 9:08 AM (reply 7 of 10)



 

are u saying that i need to get the numeric value of
the character first? how would i save it in the DB?

You need to get the numeric value at each of the places that I noted so that you can verify that the value is correct. It has nothing to do with saving it in the database.
 

Posts:11,200
Registered: 7/22/99
Re: help on processing french character with java String class  
Aug 6, 2004 11:52 AM (reply 8 of 10)



 
and displayed using system.out.println()

And to see the output from System.out.println() you use the DOS prompt, correct?

This is a known problem. The DOS prompt uses a different character encoding than the rest of the Windows operating system. To make Java adjust you have to tell it to use the DOS encoding rather than the Windows encoding. This is done by passing an extra command line argument:
java -Dfile.encoding=CP850 YourClassName
This should make É show as É instead of ╩.

The issue with the database is separate
 

Posts:10,972
Registered: 10/23/03
Re: help on processing french character with java String class  
Aug 6, 2004 12:05 PM (reply 9 of 10)



 
And anyway, they're called "Freedom characters", not "French characters"...
 

Posts:781
Registered: 5/1/01
Re: help on processing french character with java String class  
Aug 6, 2004 12:08 PM (reply 10 of 10)



 
and displayed using system.out.println()

And to see the output from System.out.println() you
use the DOS prompt, correct?

yes, i print out everything thing to dos window for debugging.

This is a known problem. The DOS prompt uses a
different character encoding than the rest of the
Windows operating system. To make Java adjust you have
to tell it to use the DOS encoding rather than the
Windows encoding. This is done by passing an extra
command line argument:
java
-Dfile.encoding=CP850 YourClassName
This
should make � show as � instead of
╩.

thanks, i will try that.

The issue with the database is separate

somehow i could store those characters in the database now. just don't why i couldn't.
 
This topic has 10 replies on 1 page.