从包含utf 8字符的属性文件中读取 [英] Reading from property file containing utf 8 character

查看:101
本文介绍了从包含utf 8字符的属性文件中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am reading a property file which consists of a message in the UTF-8 character set.

问题

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

The output is not in the appropriate format. I am using an 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, €, ¢, £, ¥}

我正在读取这样的文件

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);

以上消息的输出为

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

You can see the message in the console after the line

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

如果我能得到正确阅读此文件的任何帮助,我将负责.我可以用另一种方法读取此文件,但我希望减少代码修改.

I will be obliged if I can get any help reading this file properly. I can read this file with another approach but I am looking for less code modification.

推荐答案

Properties.load(Reader reader)中使用InputStreamReader:

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

这篇关于从包含utf 8字符的属性文件中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆