Got problem in tomcat while read xml file..

hi' i just wondering, why i always got his exception, i just want to read this file

java.io.FileNotFoundException: C:\Program Files\netbeans-5.5\enterprise3\apache-tomcat-5.5.17\bin\dbconfig.xml (The system cannot find the file specified)

at java.io.FileInputStream.open(Native Method)......

How to read dbconfig.xml?

Right now i put dbconfig.xml in /webapps/myapp/web-inf/classes/dbconfig.xml. but i always got that exception, why?

if i put my dbconfig.xml inapache-tomcat-5.5.17\bin directory (see exception...), i got no exception.

So, is there anyway to read dbconfig.xml while i put it in/webapps/myapp/web-inf/classes/ directory?

This is my code :

public UserWrapper(){

builder =new SAXBuilder();

try{

doc = builder.build(new File("dbconfig.xml"));

rootElement = doc.getRootElement();

System.out.println(rootElement.getChildText("db-driver"));

}catch (JDOMException e){

e.printStackTrace();

}catch (IOException e){

e.printStackTrace();

}

}

Thanks a lot..

[1567 byte] By [hudoqa] at [2007-11-27 8:45:40]
# 1

The JVM looks for files relative to the pwd or directory in which it was started. For Tomcat it is the bin directory. That is why it can find dbconfig.xml in the bin directory but not the classes directory.

You have two choices.

1; give the path to the file inth eclasses directory. You can use the ServletContext getRealPath method to build this path.

2: Since the file is in the classpath you can use the Class getResourceAsStream method to get an InputStream to the file. Then see if the SAXBuilder class has an api that takes an InputStream.

tolmanka at 2007-7-12 20:46:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
hey, thanks for the answer, i will try to use both of it. i will post the result next.thanks a lot...
hudoqa at 2007-7-12 20:46:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
hey, sory for late report. after looking for the correct way to implements this thing, i finally find how to solve it, i'm using Classloader to get the proper path. After path already set, just read it with inputstream to the SAXBuilder. Thanks....
hudoqa at 2007-7-12 20:46:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...