I have a problem getting localized value (a UTF-8 string) from the properties file.
Here is what i did ..//properties file containing
//name=हिन्दी
public static void main(String[] args)
{
File f = new File("path\\to\\properties\\file");
Properties p = new Properties();
try
{
p.load(new InputStreamReader(new FileInputStream(f),Charset.f开发者_JAVA百科orName("UTF-8")));
}
catch(IOException iox) {}
System.out.println(p.getProperty("name")); //outputs null
System.out.println(p.toString()); //outputs { name= हिन्दी }
}
Thanks
If the last line actually outputs name= हिन्दी
then it looks like there's something wrong with the key String in the properties file; perhaps in includes some invisible whitespace character or one of the charaters of "name" is not the regular latin letter but something that looks like it. Take a look at the properties file in a hex editor.
Your problem is here:
catch(IOException iox) {}
this is called "mutual failure". Never do this. Your code that loads properties from file fails and throws exception and you even do not know about this. Add e.printStackTrace()
and move code that prints properties values into the try/catch
block. See the exception and fix the bug. I believe that your file path is wrong, so you will get FileNotFoundException
or probably you do not have access rights to this file.
精彩评论