Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

reading unicode value of a character

810318Nov 5 2010 — edited Nov 5 2010
Hi all,

I'm trying to read a file which is written in albanin. So obviously I implemented a way to read them in unicode and then store then in a Arraylist and again print them back.

here is the code i tried:

FileInputStream in;
String str = null;
try
{
in = new FileInputStream( "C:\\Users\\Administrator\\Desktop\\d1.txt" );
InputStreamReader inputStreamReader = new InputStreamReader(in);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

str = bufferedReader.readLine();
}
catch ( Exception e )
{
e.printStackTrace();
}

StringBuffer ostr = new StringBuffer();

for(int i=0; i<str.length(); i++)
{


ostr.append("\\u") ;
String hex = Integer.toHexString(str.charAt(i) & 0xFFFF); // Get hex value of the char.

for(int j=0; j<4-hex.length(); j++) // Prepend zeros because unicode requires 4 digits
ostr.append("0");
ostr.append(hex.toLowerCase()); // standard unicode format.

}

System.out.println(new String(ostr));




Although the unicode of letter "Ë" is 00cb, programme gives the value as "\ufffd" but for other normal characters it shows correct values(for english characters)


How can i solve this problem?


thanks in advance....
This post has been answered by 810801 on Nov 5 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 3 2010
Added on Nov 5 2010
7 comments
301 views