1 package com.ca.commons.cbutil; 2 3 import java.io.*; 4 import java.util.Properties ; 5 6 11 public class CBPropertyFileReader 12 { 13 16 private String propFileName = null; 17 18 21 private Properties properties = null; 22 23 28 public CBPropertyFileReader(String propFileName) 29 throws IOException 30 { 31 this.propFileName = propFileName; 32 File propFile = new File(propFileName); 33 loadPropertyFile(propFile); 34 } 35 36 41 public CBPropertyFileReader(File propFile) 42 throws IOException 43 { 44 if (propFile == null || !propFile.exists()) 45 throw new IOException("File does not exist."); 46 47 propFileName = propFile.getAbsolutePath(); 48 loadPropertyFile(propFile); 49 } 50 51 56 private void loadPropertyFile(File propFile) 57 throws IOException 58 { 59 if (propFile.exists() == false) 61 throw new IOException("Cannot find the properties file: " + propFileName); 62 63 properties = new Properties (); 64 properties.load(new FileInputStream(propFile)); 65 } 66 67 73 public String getValue(String key) 74 { 75 return properties.getProperty(key); 76 } 77 78 81 public String getPropFileName() 82 { 83 return propFileName; 84 } 85 86 91 public void setPropFileName(String propFileName) 92 { 93 this.propFileName = propFileName; 94 } 95 96 99 public Properties getProperties() 100 { 101 return properties; 102 } 103 104 109 public void setProperties(Properties properties) 110 { 111 this.properties = properties; 112 } 113 } 114 | Popular Tags |