Click here to Skip to main content
14,935,580 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends
how to read Unicode charcater
i try but character is shown (?????)
if you have sample give me
thanks alot
Updated 22-Jul-12 2:04am
Richard MacCutchan 22-Jul-12 8:12am
char variables in Java are already Unicode. Please show the code that you are using to read your file and display it.
woutercx 22-Jul-12 8:15am
It depends on what you're trying to display the characters.
woutercx 22-Jul-12 8:15am
Is it a form, a textbox that you're showing the characters on?

Files are written with a specific character set.

And "unicode" is not enough to identify which character set is is use. Common (but not the only possibility) include 8 bit and 16 bit variations, where the 16 bit variation includes byte order.

AFTER you determine the character set then you open the file using the appropriate encoding.

ONE example of opening a file like that with a specific encoding is as follows

InputStreamReader(stream, "UTF-8")

Further keep in mind that just because you read it correctly it does not mean that you can display it correctly. Those are two distinct parts.
quick and simple:

Reader oReader = new InputStreamReader(new FileInputStream("file"), "UTF-8"));
String strUTF8Text = null;

while(true){ // infinit loop
  String strLine = oReader.readLine();
  if(null== strLine) break; // exit point
  strUTF8Text += strLine;

Please also read here for much more information about "Byte Encodings and Strings"[^] in the Java Tutorials.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900