title: How to personally format a properties file in java?
body: <p>I'm using properties class from java to save some configuration for my application. It's the first time I'm using properties so please be gentle with me :)</p>
  
  <p>I can insert and retrieve data from the properties, no problem, but I want to insert the data as something like:</p>
  
  <p>Properties file:</p>
  
  <pre><code>#Header generated by java ~ this is fine, I don't care
  
  #Server 1 configuration
  url=192.168.1.1
  port=6546
  username=max
  password=123
  
  #Server 2 configuration
  url=192.168.2.1
  port=6454
  username:dude
  password:123
  
  #And so on...
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>public void setProp(String host, String port, String user, String pass, 
                             String host2, String port2, String user2, String pass2)
  {
          try{
              prop.setProperty("host", host);
              prop.setProperty("port", porto);
              prop.setProperty("username", user);
              prop.setProperty("password", pass);
  
              prop.setProperty("host2", host2);
              prop.setProperty("port2", porto2);
              prop.setProperty("username2", user2);
              prop.setProperty("password2", pass2);
  
              config.store(new FileOutputStream("configuration.properties"), "Server 1 Configuration");
  
          }catch (Exception e) {
              JOptionPane.showMessageDialog(null,"Error: "+e.getMessage());
          }
  }
  </code></pre>
  
  <p>EDIT:
  @Nathan Not close to what I pretend. The properties file generated is:</p>
  
  <pre><code>#Wed Apr 03 14:03:57 BST 2013 
  server1.url=192.168.1.1 
  server1.port=80 
  server2.password=qqq 
  server1.user=root 
  server2.port=88 
  server2.user=dude 
  server1.pass=123 
  server2.url=192.168.2.1
  </code></pre>
  
  <p>I would be looking for something like:</p>
  
  <pre><code>#Wed Apr 03 14:03:57 BST 2013 
  #Server 1 details
  server1.url=192.168.1.1 
  server1.port=80 
  server1.user=root 
  server1.pass=123 
  
  #Server 2 details:
  server2.password=qqq 
  server2.port=88 
  server2.user=dude 
  server2.url=192.168.2.1
  </code></pre>
  
  <p>I dont even care if the order is not right (like password above url and under port, etc) I just need them to be grouped by, as they are in my example now.</p>