从包含utf 8字符的属性文件中读取

Som*_*Som 13 java encoding parsing utf-8

我正在读取一个属性文件,该文件由UTF-8字符集中的消息组成.

问题

输出格式不正确.我正在使用InputStream.

属性文件看起来像

username=LBSUSER
password=Lbs@123
url=http://localhost:1010/soapfe/services/MessagingWS
timeout=20000
message=Spanish character are = {á é í, ó,ú ,ü, ñ, ç, å, Á, É, Í, Ó, Ú, Ü, Ñ, Ç, ¿, °, 4° año = cuarto año, €, ¢, £, ¥}
Run Code Online (Sandbox Code Playgroud)

我正在读这样的文件,

Properties props = new Properties();
props.load(new FileInputStream("uinsoaptest.properties"));
String username = props.getProperty("username", "test");
String password = props.getProperty("password", "12345");
String url = props.getProperty("url", "12345");
int timeout = Integer.parseInt(props.getProperty("timeout", "8000"));
String messagetext = props.getProperty("message");
System.out.println("This is soap msg : " + messagetext);
Run Code Online (Sandbox Code Playgroud)

以上消息的输出是

在此输入图像描述

您可以在行后的控制台中看到该消息

{************************ SOAP MESSAGE TEST***********************}

如果我能得到任何正确阅读此文件的帮助,我将不得不承担责任.我可以用另一种方法读取此文件,但我正在寻找更少的代码修改.

Wür*_*paß 45

使用InputStreamReaderwith Properties.load(Reader reader):

FileInputStream input = new FileInputStream(new File("uinsoaptest.properties"));
props.load(new InputStreamReader(input, Charset.forName("UTF-8")));
Run Code Online (Sandbox Code Playgroud)