Home >Java >javaTutorial >Solution to the problem of Chinese garbled characters when Java reads the properties configuration file

Solution to the problem of Chinese garbled characters when Java reads the properties configuration file

高洛峰
高洛峰Original
2017-01-12 10:30:331698browse

As shown below:

public static String getConfig(String key) {
    Properties pros = new Properties();
    String value = "";
    try {
      pros.load(new InputStreamReader(Object.class.getResourceAsStream("/properties.properties"), "UTF-8"));
      value = pros.get(key).toString();
    } catch (IOException e) {
      log.error(e.getMessage());
    }
    return value;
  }

The above is the solution to the problem of Chinese garbled characters when Java reads the properties configuration file brought by the editor. I hope you will use it. Support PHP Chinese website~

For more solutions to the problem of Chinese garbled characters when Java reads the properties configuration file, please pay attention to the PHP Chinese website for related articles!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn