Hi,
I am trying to read a property file using a sample code as below.
The property file is packaged as a resource in the same jar. Problem is that I am getting a java.io.IOException: Stream closed on "props.load" with Java 6. Strangely, the same piece of code works properly with Java 5.
package test;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
/**
* This class is used to read the values from the property files
*/
final public class PropertyReader {
private static final String FILE_NAME="test.properties";
private static PropertyReader instance = null;
private java.util.logging.Logger Logger = java.util.logging.Logger.getLogger(this.getClass().getPackage().getName());
static
{
instance = new PropertyReader();
}
private PropertyReader() {}
public static PropertyReader getInstance()
{
return instance;
}
/**
* This method Reads the property file and returns
* the property object.
* @return Property object.
*/
public synchronized Properties getProperties() {
Properties prop = null;
InputStream propReadStream = null;
try {
propReadStream = new BufferedInputStream(this.getClass().getResourceAsStream("/" + FILE_NAME));
Logger.info(this.getClass().getName(), methodName, "buffer input is >>.."+propReadStream.toString());
prop = new Properties();
prop.load(propReadStream);
Logger.info(this.getClass().getName(), methodName, "prop loading is done>>.." + prop.toString());
} catch (final IOException e) {
Logger.error(this.getClass().getName(), methodName, "IOException received >>>>>:"+e.getMessage());
}catch(final Exception e)
{
Logger.error(this.getClass().getName(), methodName, "Exception received. Type:"+e.getClass().getName()+" Message:"+e.getMessage());
}
finally {
if (propReadStream != null) {
try{
propReadStream.close();
}
catch(IOException e){
Logger.error(this.getClass().getName(), methodName, "Exception received. Type:"+e.getClass().getName()+" Message:"+e.getMessage());
}
}
}
return prop;
}
}
Could someone please help in identifying the problem here?
Thanks in advance.