java 读取系统配置文件

来源:互联网 发布:手机直播软件大全 编辑:程序博客网 时间:2024/06/05 07:02
import java.io.FileInputStream;import java.io.IOException;import java.util.Properties;public class Test {public static void main(String[] args) throws IOException {Test t =new Test();t.a();}public void a() throws IOException{ClassLoader classLoader = getClass().getClassLoader();String configFilePath = classLoader.getResource("config.properties").getFile();    FileInputStream is = null;        Properties dbproperties = new Properties();        is = new FileInputStream(configFilePath);          dbproperties.load(is);        String db_url = dbproperties.getProperty("db_url").toString();             System.out.println(db_url);}}

0 0