Home > Java > javaTutorial > body text

Simple example of Java reading properties configuration file

黄舟
Release: 2017-09-19 10:00:32
Original
1349 people have browsed it

This article mainly introduces the method of java to simply read the properties configuration file, involving java's loading of properties configuration and related operation skills of file attribute reading. Friends in need can refer to the example of this article

Describes how to simply read the properties configuration file in Java. Share it with everyone for your reference, the details are as follows:

Read the configuration file, the summary is as follows


import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
public class loadConf {
  private Properties prop = new Properties();
  private void loadconf() throws FileNotFoundException, IOException {
    String path = "com/jlc/util/user.properties";
    prop.load(loadConf.class.getClassLoader() .getResourceAsStream(path));
  }
  public loadConf() throws FileNotFoundException, IOException {
    loadconf();
  }
  public boolean chkProperty(String _key) {
    return prop.containsKey(_key);
  }
  public String getProperty(String _key) {
    return prop.getProperty(_key);
  }
  public static void main(String[] args) throws FileNotFoundException, IOException {
    loadConf mycnf = new loadConf();
    System.out.println(mycnf.chkProperty("address"));
    System.out.println(mycnf.getProperty("poart"));
  }
}
Copy after login

The above is the detailed content of Simple example of Java reading properties configuration file. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!