Forums Register Login

Catching IOExceptions error

+Pie Number of slices to send: Send
Hi,
I have got a piece of code(method) below that reads a properties file. For some reason, I am getting an error when compiling, at the point where I try to catch the IOException (exception needs to be caught because the Properties.load class throws it). Does anyone know why I am getting this please?

//reading properties file test
public void readXML(){
Properties config = new Properties();
String PROPS_FILE = "/location/file.properties";
try {
Class clazz = LdapConnect.class;
config.load(clazz.getResourceAsStream(PROPS_FILE));
}
catch (IOException e) {
System.err.println("Caught IOException: " +e.getMessage());
}
catch (NullPointerException npe) {
System.err.println("Caught NullPointerException: " +npe.getMessage());
}


String value = config.getProperty("field1");
String value1 = config.getProperty("field2");
System.out.println("THE VALUE IS :"+value);
System.out.println("THE VALUE1 IS :"+value1);
}
+Pie Number of slices to send: Send
As written, the code compiles just fine (assuming that java.io.IOException and java.util.Properties have been imported.)
[ January 15, 2004: Message edited by: Ernest Friedman-Hill ]
+Pie Number of slices to send: Send
Sorry,
you were right - I forgot to import java.io!
Thanks for your help.
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 507 times.
Similar Threads
Need an understanding why I am getting "incompatiable types"
Why Null Pointer Exception?
Using Server Installed JRE For JNLP
log4j:ERROR Ignoring configuration file [WEB-INF/log4j.properties
java.io.FileNotFoundException: FileOutputStream error?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:28:24.