2017-09-26 82 views
-1

可以說我有一個文件名config.yml,我使用properties對象來獲取屬性。我想通過記事本++和普通記事本來編輯文件,它會保留文件已經存在的內容。程序運行時文件自動更新

Properties prop = new Properties(); 
prop.setProperty("test", "20"); 
prop.store(file, null); 
System.out.println(prop.getProperty("test"); 

輸出是20,但我希望它改變到任何文件說它是。如何在像記事本++這樣的程序中編輯文件,並獲得像30這樣的不同輸出作爲示例?

+1

目前還不清楚你在問什麼,你能否澄清你的問題?另外,[YAML](http://yaml.org/)文件與Java屬性文件完全不同。 –

+1

[如何重新加載java中的屬性文件]可能的重複(https://stackoverflow.com/questions/9924502/how-to-reload-properties-file-in-java) – kryger

回答

0

要閱讀屬性文件,我創建了一個簡單的程序,在控制檯上顯示其內容。

public static Properties getProp() throws IOException { 
    Properties props = new Properties(); 
    FileInputStream file = new FileInputStream(
      "./properties/dados.properties"); 
    props.load(file); 
    return props; 

} 

public static void main(String args[]) throws IOException { 
    String test; 

    Properties prop = getProp(); 

    test = prop.getProperty("test"); 

    System.out.println("Test = " + test); 

} 
相關問題