Java Store_java之Properties集合中的方法store
各位小伙伴們大家好,在之前的文章中,小編介紹了使用Properties集合存儲(chǔ)數(shù)據(jù),這次小編要介紹的是Properties集合中的方法store,具體如下:
可以使用Properties集合中的方法store,把集合中的臨時(shí)數(shù)據(jù),持久寫入到硬盤中存儲(chǔ)
void store(OutputStream out,String comments)
void store(Writer writer,String comments)
參數(shù):
OutputStream out:字節(jié)輸出流,不能寫入中文
Writer writer:字符輸出流,可以寫中文
String comments:注釋,用來(lái)解釋說(shuō)明保存的文件是做什么用的,不能使用中文,會(huì)產(chǎn)生亂碼,默認(rèn)是Unicode編碼,一般使用“”空字符串
常用步驟:
1. 創(chuàng)建Properties集合對(duì)象,添加數(shù)據(jù)
2. 創(chuàng)建字節(jié)輸出流/字符輸出流,構(gòu)造方法中綁定要輸出的目的地
3. 使用Properties集合中的方法store,把集合中的臨時(shí)數(shù)據(jù),持久寫入到硬盤中
4. 釋放資源
代碼如下:
public class Demo01Properties {
public static void main(String[] args) throws IOException {
show02();
}
public static void show02() throws IOException {
//創(chuàng)建Properties集合對(duì)象,添加數(shù)據(jù)
Properties p=new Properties();
//使用Properties集合往集合里面添加數(shù)據(jù)
p.setProperty("蛋撻", "egg tart");
p.setProperty("泡芙", "puff");
p.setProperty("tea with mike", "奶茶");
//2.創(chuàng)建字節(jié)輸出流/字符輸出流,構(gòu)造方法中綁定要輸出的目的地
FileWriter fw=new FileWriter("D://a.txt");
//3.使用Properties集合中的方法store,把集合中的臨時(shí)數(shù)據(jù),持久寫入到硬盤中
p.store(fw, "save data");
//4.釋放資源
fw.close();
}
關(guān)于Properties集合中的方法store,就是把集合中的臨時(shí)數(shù)據(jù),持久寫入到硬盤中,還有OutputStream out:字節(jié)輸出流,不能寫入中文,這一點(diǎn)大家要注意哦。小編就先說(shuō)到這里了,希望這篇文章可以幫到大家,也歡迎各位小伙伴補(bǔ)充和糾錯(cuò)。
與50位技術(shù)專家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的Java Store_java之Properties集合中的方法store的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 怀化去巴音郭楞蒙古自治州沙伊东香梨园途径
- 下一篇: 油茶面怎么做 教你制作美味的油茶面?