Home > Java > javaTutorial > body text

Share how to read configuration files in java?

零下一度
Release: 2017-07-18 10:24:50
Original
1524 people have browsed it

分享在java中如何读取配置文件?下面就为大家介绍一下,代码如下:

public class PropertyUtil {
    public static final Properties PROP = new Properties();

    /**
     * 读取配置文件的内容(key,value)
     * 
     * @param key
     * @return key对应的value
     */
    public static String get(String key) {
        if (PROP.isEmpty()) {
            try {
                InputStream in = PropertyUtil.class.getResourceAsStream("/config.properties");
                PROP.load(in);
                in.close();
            } catch (Exception e) {}
        }
        return PROP.getProperty(key);
    }
}
Copy after login
  • 在resources文件下新建config.properties文件

websitepath=E:\\code\\landtax\\landtax\\
standardcondition=\"C_CD\"<=0.2
filePathTDQS=D:\\webspace\\import\\\u571F\u5730\u6743\u5C5E\u4FE1\u606F.xlsx
Copy after login
  • 调用方法

String filePathTDQS = PropertyUtil.get("filePathTDQS");
Copy after login

The above is the detailed content of Share how to read configuration files in java?. 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!