[jdom-interest] testing for existance of xml file

Olivier Coppel olivier.coppel at akazi.com
Tue Jun 25 09:01:51 PDT 2002


I think it's not a jdom problem. Before calling "builder.build", try to open
the xml file. For example, if you use a "FileReader" class to load your xml
file, you must write :

try {
  FileReader f = new FileReader("/usr/local/tomcat/myfile2.xml");
}
catch (FileNotFoundException e) {
 ....
}

If file is not found an exception is thrown.

I hope that will help you.

Bye

Olivier Coppel




-----Message d'origine-----
De : jdom-interest-admin at jdom.org
[mailto:jdom-interest-admin at jdom.org]De la part de Paul Phillips
Envoye : mardi 25 juin 2002 17:16
A : jdom-interest at jdom.org
Objet : [jdom-interest] testing for existance of xml file


I'm sure this is an easy question.  However, I am feeling my way in jdom,
so pointers are appreciated!

In code like this...

try {
		SAXBuilder builder = new SAXBuilder();
		Document aDocument = builder.build(new
File("/usr/local/tomcat/myfile2.xml"));
		Element rootElement = aDocument.getRootElement();
		Element childElement = rootElement.getChild("childElement");
		result = childElement.getText();
	} catch(JDOMException e) {

	} catch(NullPointerException e) {

	}

What is the best way to test for the existance of myfile2.xml.  If it
doesn't exist, I want to create it.  should I test to see if aDocument is
null?

Thanks
Paul Phillips
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com




More information about the jdom-interest mailing list