[jdom-interest] SAXbuilder need a special path to access a file?

Brett McLaughlin brett at newInstance.com
Mon Aug 20 13:11:42 PDT 2001


You can use a URL from the file:

Document doc = builder.build(file.toURL());

You're passing in the path to the file as a String, but if you look at the
Javadocs, the String argument to SAXBuilder.build() must be a URL. So you'd
want something like:

Document doc = builder.build(file.toURL().toString());

Hope that helps.
---
Brett McLaughlin
Enhydra Strategist   http://www.enhydra.org
Lutris Technologies http://www.lutris.com
O'Reilly Author       http://www.oreilly.com/catalog/javaxml2
----- Original Message -----
From: "Justin Wall" <jwall at interactivesites.com>
To: <jdom-interest at jdom.org>
Sent: Monday, August 20, 2001 2:57 PM
Subject: [jdom-interest] SAXbuilder need a special path to access a file?


>
> I know this sounds trivial, but I've been staring at this since
> Thursday.  I can't get the SAXbuilder to read a file.  Does the SAXbuilder
> need a path set somewhere? I don't know what changed in my program or
> IDE(I'm using Forte) to get this error, but this was working fine
> earlier.  I'm parsing a directory for filenames and then I pass the file
to
> the builder.
>
> output:
> File: f:\thxml\pioreport.xml (6779)
> reading: f:\thxml\pioreport.xml
> Error with: f:\thxml\pioreport.xml
> Error on line 0: File "f:\thxml\pioreport.xml" not found.
>
> This is the code that generates those lines:
> //Set root dir  !!DONT FORGET 2 BACKSLASHES
> String dir = "f:\\thxml";
> File file1 = new File(dir) ;
> // Get all the files and directory under your diretcory
> File[] strFilesDirs = file1.listFiles();
>
> System.out.println( "File: " + strFilesDirs[i] + " (" +
> strFilesDirs[i].length( ) + ")" );
> parseFile(strFilesDirs[i].getPath());
>
> public static void parseFile(String file1) { ...
> SAXBuilder saxBuilder = new SAXBuilder();
> System.out.println("reading: " + file1);
> //create DOM object
> Document xtfDoc = saxBuilder.build(file1);
>
>
>
> in the catch block:
> System.out.println("Error with: " + file1);
> System.out.println(e.getMessage());
>
>
>
> Thanks,
>
> Justin Wall
>
> _______________________________________________
> 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