Reading UTF-8

HI, I need read properties file of different lang.

when i try to run following code , i am not getting proper value .

Thanks in advance

import java.io.*;

import java.lang.*;

import java.util.*;

publicclass check{

/**

* @param args

*/

publicstaticvoid main(String[] args){

// TODO Auto-generated method stub

try{

BufferedReader in =new BufferedReader(new InputStreamReader(new FileInputStream("es.properties"),"UTF-8"));

String line =null;//not declared within while loop

System.out.println(System.getProperty("file.encoding"));

Properties pi = System.getProperties();

pi.put ("file.encoding","UTF-8");// To add a new one

System.setProperties(pi);

System.out.println(System.getProperty("file.encoding"));

while (( line = in.readLine()) !=null){

String str = in.readLine();

//byte[] transbyte = str.toString().getBytes("UTF-8");

//String fieldStringValue2 = new String(transbyte, "UTF-8");

String UTF8Str =new String(str.getBytes(),"UTF-8");

System.out.println(UTF8Str);

}

}catch (UnsupportedEncodingException e)

{

System.out.println("unsupport"+e.getMessage());

}

catch (IOException e){

System.out.print("Io"+e.getMessage());

}

}

}

[2699 byte] By [finding_dpia] at [2007-11-27 1:25:41]
# 1

Actually, you don't need all this stuff. You have correctly set that you want to read UTF-8 when creating the InputStreamReader:BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("es.properties"), "UTF-8"));

Moreover, you don't need your UTF8Str. There is no encoding related to String objects.

Waht makes you think the string (str) is not read correctly? Is is because it is not printed as expected on the console ?

I guess the only problem you have is that your console doesn't support special characters, and is therefore unable to print them correctly. And I'm afraid there is no way to overcome this, unless your console charset can be configured, or you use another console.

TimTheEnchantora at 2007-7-12 0:18:54 > top of Java-index,Java Essentials,Java Programming...