• Post Reply Bookmark Topic Watch Topic
  • New Topic

Catching IOExceptions error  RSS feed

 
Kamal Patel
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Kamal Patel
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry,
you were right - I forgot to import java.io!
Thanks for your help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!