How can I add the content into properties file using java code?
1 posts in topic
Flat View  Flat View

Posted By:   dileep_kumar
Posted On:   Tuesday, May 30, 2006 09:24 AM

Hi all,

Please give me hint or guide how to start, to write the java class (or any other approach) to search all the properties file in the *.particular folder and add same content in each and every *.properties file. It would be great if u post some code or the similar links

Re: How can I add the content into properties file using java code?

Posted By:   Anonymous  
Posted On:   Tuesday, May 30, 2006 09:30 PM

import java.io.*;
import java.util.*;

public class PropertyFiles {

public void addProperty(File propFileName, String key, String value) throws Exception{

//loading an existing property file in a properties object
FileInputStream fin = new FileInputStream(propFileName);
Properties props = new Properties();

//adding a proprty (key=value) to a properties obj
props.setProperty(key, value);

//save this new value to the original property file
FileOutputStream fout = new FileOutputStream(propFileName);
props.store(fout, "Modified Property File");


public static void main(String a[]) throws Exception {
String dirPath = "e:/projects/test";
File dirFile = new File(dirPath);
PropertyFiles file = new PropertyFiles();

if(dirFile.isDirectory()) {

File[] propFiles = dirFile.listFiles(new PropertyFileFilter());

for(int i=0; i
file.addProperty(propFiles[i], "hello", "value");

}//end if


static class PropertyFileFilter implements FileFilter {
public boolean accept(File pathname) {
if(pathname.getName().endsWith("properties")) {
return true;

return false;

}//end class

About | Sitemap | Contact