How to write values in a properties file through java code

前端 未结 4 1918
庸人自扰
庸人自扰 2020-11-30 09:30

I have an issue.

I have a properties file. I want to store some values in that file and will implement in the code whenever it is required. Is there any way to do t

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 10:18

    This work for me.

        Properties prop = new Properties();
    
                    try {
                            InputStream in = new FileInputStream("src/loop.properties");
                            prop.load(in);
                        } catch (IOException ex) {
                           System.out.println(ex);
                        }
               //Setting the value to  our properties file.
               prop.setProperty("LOOP", "1");
               //Getting the value from  our properties file.
               String value = prop.getProperty("LOOP").trim();
    
                    try {
                            prop.store(new FileOutputStream("src/loop.properties"), null);
                        } catch (IOException ex) {
                           System.out.println(ex);
                        }
    

提交回复
热议问题