-1

I have a cluster.properties file with contents :

master=1.2
first.node=
second.node=10.20.30.30

I want to replace these properties with some different value. How can I do this this?

My method look like replaceProp(String filePath, String prop, String newValue)

akash
  • 22,664
  • 11
  • 59
  • 87
Shashi Ranjan
  • 1,491
  • 6
  • 27
  • 52
  • 1
    Do you know how to actually read and write to a file? It should be easy if you do. If you don't, there are countless tutorials/SO questions one Google search away... – bcsb1001 Sep 07 '15 at 15:52
  • Thanks! I got some answer at http://stackoverflow.com/questions/15337409/updating-property-value-in-properties-file-without-deleting-other-values – Shashi Ranjan Sep 07 '15 at 16:03

1 Answers1

0

One way of doing this could be:

Read Properties:

Properties properties = new Properties();
FileInputStream fis=new FileInputStream("cluster.properties");
properties.load(fis);
fis.close();

Replace:

properties.set("master", "1.2.3")
...

Save back:

FileOutputStream fos=new FileOutputStream("cluster.properties");
properties.store(fos,"Some meaningfule comments");
fos.close();
Sandeep Jindal
  • 14,510
  • 18
  • 83
  • 121