tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > Properties > Save Properties

Save Properties 

The following example shows storing already loaded properties into a text file.

File Name  :  
com/bethecoder/tutorials/utils/props/StoreProps.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.utils.props;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

public class StoreProps {
  /**
   @param args
   */
  public static void main(String[] args) {

    Properties prop = new Properties();
    prop.setProperty("ONE""111111");
    prop.setProperty("TWO""222222");
    prop.setProperty("THREE""333333");
    prop.setProperty("FOUR""444444");
    
    String propFile = "C:/prop_file.txt";
    String comments = "My test comments";
    
    try {
      System.out.println(prop);
      prop.store(new FileWriter(propFile), comments);
    catch (IOException e) {
      e.printStackTrace();
    }
  }
}
   

It serializes properties to text file.
It gives the following output,
{TWO=222222, FOUR=444444, ONE=111111, THREE=333333}



 
  


  
bl  br