java中讀取配置文件中數(shù)據(jù)的具體方法
更新時(shí)間:2013年06月19日 11:04:39 作者:
java中讀取配置文件中數(shù)據(jù)的具體方法,需要的朋友可以參考一下
1、先在項(xiàng)目中創(chuàng)建一個(gè)包(如:config),再創(chuàng)建一個(gè)配置文件(如:a.properties),添加配置信息如下:
比如:
name=kaka
age=28
2、代碼:
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertyTest {
public static void main(String[] args) {
PropertyTest loadProp = new PropertyTest();
InputStream in = loadProp.getClass().getResourceAsStream("/config/a.properties");
Properties prop = new Properties();
try {
prop.load(in);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(prop.getProperty("name"));
System.out.println(prop.getProperty("age"));
}
}
比如:
復(fù)制代碼 代碼如下:
name=kaka
age=28
2、代碼:
復(fù)制代碼 代碼如下:
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertyTest {
public static void main(String[] args) {
PropertyTest loadProp = new PropertyTest();
InputStream in = loadProp.getClass().getResourceAsStream("/config/a.properties");
Properties prop = new Properties();
try {
prop.load(in);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(prop.getProperty("name"));
System.out.println(prop.getProperty("age"));
}
}
相關(guān)文章
從0開始學(xué)習(xí)大數(shù)據(jù)之java spark編程入門與項(xiàng)目實(shí)踐
這篇文章主要介紹了從0開始學(xué)習(xí)大數(shù)據(jù)之java spark編程入門與項(xiàng)目實(shí)踐,結(jié)合具體入門項(xiàng)目分析了大數(shù)據(jù)java spark編程項(xiàng)目建立、調(diào)試、輸出等相關(guān)步驟及操作技巧,需要的朋友可以參考下2019-11-11Sentinel Dashboard限流規(guī)則保存方式
這篇文章主要介紹了Sentinel Dashboard限流規(guī)則保存方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06Spring JdbcTemplate執(zhí)行數(shù)據(jù)庫(kù)操作詳解
JdbcTemplate是Spring框架自帶的對(duì)JDBC操作的封裝,目的是提供統(tǒng)一的模板方法使對(duì)數(shù)據(jù)庫(kù)的操作更加方便、友好,效率也不錯(cuò),這篇文章主要介紹了Spring JdbcTemplate執(zhí)行數(shù)據(jù)庫(kù)操作,需要的朋友可以參考下2022-10-10使用vscode搭建javaweb項(xiàng)目的詳細(xì)步驟
我個(gè)人是很喜歡VsCode的,開源免費(fèi)、功能全面,所以為了方便,我把我?guī)缀跛械倪\(yùn)行都集成到了VsCode上來(lái),JavaWeb也不例外,下面這篇文章主要給大家介紹了關(guān)于使用vscode搭建javaweb項(xiàng)目的相關(guān)資料,需要的朋友可以參考下2022-11-11Java 泛型 Generic機(jī)制實(shí)例詳解
這篇文章主要為大家介紹了Java 泛型 Generic機(jī)制實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11