java读取Properties文件时碰到问题
1. 资源文件中的key对应的value需要换行显示时,若直接回车,则同样丢掉回车后的部分
针对上述问题找到如下解决办法:
1. 内容过长需要换行时拼接个/斜杠,这样/后的内容后正常显示
package test;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertiesTest2
{
public static void main(String[] args)
{
Properties properties = new Properties();
try
{
InputStream inputStream = PropertiesTest2.class.getClassLoader().getResourceAsStream("config.properties");
properties.load(inputStream);
inputStream.close(); //关闭流
}
catch (IOException e)
{
e.printStackTrace();
}
String key1 = properties.getProperty("config.iphone.apns.certificatePath");
System.out.println(key1);
}
}
config.properties的内容:
config.iphone.apns.certificatePath=my name is tt /
i will test it.
行动以上代码显示:
my name is tt i will test it.