亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

.properties 文件被覆蓋。如何克服呢?

.properties 文件被覆蓋。如何克服呢?

吃雞游戲 2023-04-13 15:04:25
java 中的 config.properties 文件在每次執行后都會被覆蓋。我想要的是,以前的數據也應該與新的更新數據一起保存。下面是我用來將值存儲到 config.properties 文件的代碼。我的 config.properties 文件已經包含了一些數據。try (OutputStream output = new FileOutputStream("path\\to\\config.properties")) {            Properties prop = new Properties();            // set the properties value            prop.setProperty("IFCode", "34253");            // save properties to project root folder            prop.store(output, null);            System.out.println(prop);        } catch (IOException io) {            io.printStackTrace();        }這是我的 config.properties 文件數據,它已經存在于那里:-#Tue Jul 23 02:38:34 EDT 2019File=987Read=098現在,當我運行上面的代碼時,這些已經可用的數據被省略了,新的數據是這樣寫的:-#Tue Jul 23 02:38:34 EDT 2019IFCode=34253我想要的基本上是:-#Tue Jul 23 02:38:34 EDT 2019File=987Read=098IFCode=34253如何使用java克服這個問題?
查看完整描述

2 回答

?
慕田峪9158850

TA貢獻1794條經驗 獲得超8個贊

嘗試為您的 FileOutputStream 添加布爾附加參數:

OutputStream?output?=?new?FileOutputStream("path\\to\\config.properties",?true)

FileOutputStream(File file, boolean append) 創建文件輸出流以寫入由指定的 File 對象表示的文件。


查看完整回答
反對 回復 2023-04-13
?
皈依舞

TA貢獻1851條經驗 獲得超3個贊

這是解決方案:


  try (OutputStream output = new FileOutputStream("path\\to\\config.properties",true)) {


    Properties prop = new Properties();


    // set the properties value

    prop.setProperty("IFCode", "34253");


    // save properties to project root folder

    prop.store(output, null);


    System.out.println(prop);


}  catch (FileNotFoundException e) {

    e.printStackTrace();

} catch (IOException e) {

    e.printStackTrace();

}


查看完整回答
反對 回復 2023-04-13
  • 2 回答
  • 0 關注
  • 196 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號