1.String转Properties这个容易有乱码
public Properties load(String propertiesString) { Properties properties = new Properties(); try { properties.load(new ByteArrayInputStream(propertiesString.getBytes())); } catch (IOException e) { logger.error(ExceptionUtils.getFullStackTrace(e)); } return properties; }
2.由于 Properties 实现了Map 接口, 所以有最最简单的 ,强制转换。
Properties properties = new Properties(); properties.setProperty("StrictHostKeyChecking", "no"); properties.setProperty("app.version", "1.0"); Map<String, String> map = new HashMap<String, String>((Map) properties);
3.乱码解决
public Properties load(String propertiesString) { Properties properties = new Properties(); properties.load(new StringReader(propertiesString)); return properties; }