UTF-8 encodes Java strings into properties
I have a single UTF - 8 encoded string, which is a series of key - value pairs that need to be loaded into the properties object I noticed that I was using the garbled code of my initial implementation. After a Google search, I found that this question indicates that my problem is - basically, the attribute of iso-8859-1 is used by default This implementation looks like
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;
}
There is no specified code, so my problem For my question, I don't know how to link / create a reader / InputStream combination to pass to the user using the provided propertiesstring and specifying the encoded properties load(). I think this is mainly due to my inexperience in I / O flow and Java IO package looks like a huge IO utility library
Any suggestions are appreciated
Solution
Use reader when using strings Inputstreams are really binary data
public Properties load(String propertiesString) {
Properties properties = new Properties();
properties.load(new StringReader(propertiesString));
return properties;
}
