您的位置:首页 > 编程语言 > Java开发

java 读取系统配置文件

2015-10-12 16:56 363 查看
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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: