reading unicode value of a character
810318Nov 5 2010 — edited Nov 5 2010Hi 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....