国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Java中使用Properties配置文件的簡(jiǎn)單方法

瀏覽:4日期:2022-08-25 15:58:38

properties

Properties文件是java中的一種配置文件,文件后綴為“.properties”,文件的內(nèi)容格式是“key=value”的格式,用 # 作為注釋。

Java中使用Properties配置文件的簡(jiǎn)單方法

我的properties 文件放在路徑

Java中使用Properties配置文件的簡(jiǎn)單方法

寫與讀

向properties文件中寫入數(shù)據(jù)

//創(chuàng)建一個(gè)properties對(duì)象Properties pro = new Properties();//創(chuàng)建一個(gè)輸出流 里面路徑填寫文件的路徑OutputStream proos = new FileOutputStream('user.properties');pro.setProperty('id', '1001');pro.setProperty('username','你好');pro.setProperty('password', '123');//將數(shù)據(jù)儲(chǔ)存到文件中,第一個(gè)參數(shù)是 輸出流,第二個(gè)參數(shù)是注釋pro.store(proos,'User');proos.close();

將文件中的數(shù)據(jù)取出

Properties pro = new Properties();//創(chuàng)建一個(gè)輸出流InputStream prois = new FileInputStream('user.properties');//將文件取出 傳入一個(gè) 輸出流pro.load(prois);int id = Integer.parseInt((String) pro.get('id'));String username = (String) pro.get('username');String password = (String) pro.get('password');System.out.println(pro);System.out.println(id);System.out.println(username);System.out.println(password);prois.close();

運(yùn)行結(jié)果

Java中使用Properties配置文件的簡(jiǎn)單方法

總結(jié)

到此這篇關(guān)于Java中使用Properties配置文件的文章就介紹到這了,更多相關(guān)Java用Properties配置文件內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 通榆县| 鹰潭市| 中山市| 兰西县| 洛阳市| 寿阳县| 襄垣县| 彭州市| 澳门| 哈尔滨市| 潮安县| 澳门| 花垣县| 南昌市| 泌阳县| 思茅市| 广安市| 紫金县| 宁都县| 康平县| 古浪县| 新化县| 茌平县| 乌兰察布市| 遂宁市| 邯郸县| 平江县| 镇雄县| 韶关市| 台安县| 奉节县| 苗栗县| 和硕县| 介休市| 昭平县| 赤壁市| 太原市| 通海县| 永春县| 新晃| 兴海县|