在.Properties文件中搜索日语字符串消息

时间:2016-02-23 16:36:09

标签: java localization properties-file

我有一个日语的String消息。 我想搜索并使用键和值对与属性文件进行比较,如果与值匹配则返回Pass(日语)。在属性文件中,value是doble字节,需要在比较之前转换为japanese。不知道该怎么做。在代码下面写下.property文件。

的System.out.println(sMessage);

if(sMessage != null){

// Read Property file using file reader 
// In property file, value is in doble byte , which needs to convert to japanese before comparison. Dont know how to do that.

                 BufferedReader br = null;
                    String strLine = "";
                    try {
                        br = new BufferedReader( new FileReader("C:\\common-test\\common-test\\translationtest\\messages_ja.properties"));
                        strLine = br.readLine().toString();
                        System.out.println(strLine);
                                br.readLine();
                    } catch (FileNotFoundException e) {
                        System.err.println("Unable to find the file: fileName");
                    } catch (IOException e) {
                        System.err.println("Unable to read the file: fileName");
                    }

                    if(Arrays.equals(sMessage.getBytes(), strLine.getBytes() ))
                    {
                        ReportResults("Pass", "Toaster message for Invalid Credentials" + sMessage + " equals test from property file: " + strLine,false);
                    }
                    else{
                        ReportResults("Fail",  "Toaster message for Invalid Credentials" + sMessage + " does NOT equals test from property file: " + strLine,true);
                    }


                //ReportResults("FAIL", "Login Failed: " + sMessage, true);
                //Assert.fail("Login failed: " + sMessage);
            }

下面附带的.properties文件

WM-SM-BE-0001=\u5FC5\u8981\u306A\uFF8A\uFF9F\uFF97\uFF92\uFF70\uFF80{0}\u3092\u5165\u529B    \u3057\u3066\u4E0B\u3055\u3044
WM-SM-BE-0002=\u7121\u52B9\u306A\u8A8D\u8A3C\u3002
WM-SM-BE-0003=\uFF95\uFF70\uFF7B\uFF9E\uFF70\u306F\u65E2\u306B\u5B58\u5728\u3002
WM-SM-BE-0004=\uFF9B\uFF70\uFF99\u540D\u306F\u65E2\u306B\u5B58\u5728\u3002

1 个答案:

答案 0 :(得分:1)

属性文件始终编码为ISO-8859-1。因此,如果您想要正确可靠地读取自己的数据,则需要指定它:

 br = new BufferedReader( new InputStreamReader(new FileInputStream("C:\\common-test\\common-test\\translationtest\\messages_ja.properties"),"ISO-8859-1"));

但是,如果你想将你的字符串与属性文件的第一行完整比较。如果您只想比较该值,对于给定的密钥,请使用Properties类,为您做正确的阅读。