Monday, May 31, 2010

Read properties file in Java

the main essence of program is following method, How ever u can download a working copy form here-
http://code.google.com/a/eclipselabs.org/p/java-utility/downloads/list

public static boolean readProperties(String fileName, Properties pro) throws IOException{
try{
File f = new File(fileName);
// Check the important properties of properties file.
if(f.exists() && f.canRead() && f.isFile()){
FileInputStream in = new FileInputStream(f);
// Just load the properties file here
pro.load(in);
return true;
}
else{
logger.info(f.getAbsolutePath());
if(!f.exists())
logger.error("File not found!");
if(!f.canRead())
logger.error("Can not read the file !");
if(!f.isFile())
logger.error("Not a file !");
return false;
}
}
catch(IOException e){
logger.error("Exception while reading the properties file :"+ e.getMessage());
throw e;
}
}

1 comment:

html5 audio player said...

Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.