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

标签 java localization properties-file

我有一条日语字符串消息。 我想搜索它并将其与具有键和值对的属性文件进行比较,如果与值匹配(日语),则返回 Pass。在属性文件中,值是双字节的,在比较之前需要转换为日语。不知道该怎么做。在代码下面写下.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

最佳答案

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

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

但前提是您要将字符串与属性文件的完整第一行进行比较。如果您只想比较给定键的值,请使用 Properties 类,它会为您进行正确的读取。

关于java - 在 .Properties 文件中搜索日语字符串消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35583048/

相关文章:

java - 动态 JPA 连接

java - 直接 Java 和 Grails 之间的反射差异

java - 如何配置 EC2 以在我的 Spring Boot 应用程序中处理表情符号

PHP gettext 函数只返回原始未翻译的字符串

C# 文化敏感句识别

c - 将 LC_MESSAGES 设置为不存在的语言环境的 setlocale() 失败

grails - 使用外部配置获取多个数据源

java - 我们怎样才能在运行时编译和调试用Java编写的代码呢?

spring - spring boot应用中读取多个实体扫描包

servlets - 在基于 servlet 的应用程序中放置以及如何读取配置资源文件?