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 / General / February 2006

Tip: Looking for answers? Try searching our database.

reading DBCS data (japanese) from system.in

Thread view: 
Nirmal R - 16 Feb 2006 11:02 GMT
Hi all,

I am trying to write one java client/server application in Solaris.

I have problem in Client side.

Actually, the client will read the user data using "System.in" and send
the data to user.
It's working fine for user name in english.

The problem comes when I try to read Japanese characters.
the code used to read data is below,

           batchReader = new BufferedReader(new
InputStreamReader(System.in));
           System.out.print("User : ");
           cl = batchReader.readLine();
           System.out.println("Line >> " + cl);

           for(i = 0; i < cl.length(); i++) {
               System.out.print((int) cl.charAt(i));
               System.out.print(", ");
           }
           System.out.println("");
           batchReader.close();

for "export LANG=en_US.UTF-8", it reads the data properly,
but for "export LANG=" it prints some junk value.

rnirmal@snds1$ export LANG=en_US.UTF-8
rnirmal@snds1$ java nread
User : .company
Line >> .company
12358, 12359, 12364, 46, 99, 111, 109, 112, 97, 110, 121,

rnirmal@snds1$ export LANG=
rnirmal@snds1$ java nread
User : .company
Line >> ?????????.company
65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 46, 99,
111, 109, 112, 97, 110, 121,
rnirmal@snds1$

I need a common way to read data independent of encoding or "LANG"
value.
Please help me to fix the issue,

really appriciate your help.

Thanks,
Nirmal R.
John O'Conner - 16 Feb 2006 20:51 GMT
> The problem comes when I try to read Japanese characters.
> the code used to read data is below,
[quoted text clipped - 11 lines]
>             System.out.println("");
>             batchReader.close();

<snip>

> I need a common way to read data independent of encoding or "LANG"
> value.

You need to stop depending on the "default" encoding of your host
system. You are closely tying your input and output results to your
console encoding, which you are controlling by the LANG environment
variable.

I suggest two things:
1. Get user input from a Swing GUI. The input is guaranteed to be
Unicode characters. Display the input with a Swing GUI...the output is
Unicode rendered properly in a Swing component.
2. If you insist on reading from the console and you know that the input
is UTF-8 regardless of what the LANG setting is, then create your
InputStreamReader appropriately with a "UTF-8" charset parameter.

Regards,
John O'Conner


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



©2009 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.