Java Collection How to - Save properties with store() method








Question

We would like to know how to save properties with store() method.

Answer

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
//from w  ww  .  ja  va 2s.  c  o m
public class MainClass {
  public static void main(String args[]) throws Exception {
    Properties p = new Properties();
    p.load(new FileInputStream("test.txt"));

    p.store(new FileOutputStream("t.txt"),"no comments");
  }
}

The code above generates the following result.