This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes MalformedURLException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "MalformedURLException" Watch "MalformedURLException" New topic
Author

MalformedURLException

Dalia Sultana
Ranch Hand

Joined: Jul 16, 2006
Posts: 42
Hi,

I had an existing class to read/write an xml fle using apache's DOMParser. However after modifying the file to use sun's DOMParser, I see that only the write part works and not the read part. I get a MalformedURLException exception when trying to read the file as follows:

java.net.MalformedURLException: unknown protocol: c

Seems like it the parse method does not like the name of the file. Which starts as C:\...

This is how I am reading the file.

if(rootDocument == null){
DOMParser parser = new DOMParser();
parser.parse(getXmlFileName());
rootDocument = parser.getDocument();
}


private static String getXmlFileName(){
String userHome = System.getProperty("user.home");
return userHome+ "/Preferences/" + peferencesFile ;
}
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

That's right, a file path is not a URL. You could try to make your path into a file URL by prefixing it with "file://", although I'm never sure whether you need two or three slashes. Or you could see if the parse() method has an overloaded version that takes, for example, a File object.
 
wood burning stoves
 
subject: MalformedURLException
 
Similar Threads
Problem updating the JAR file
FileNotFoundException is thrown when i try to read a file?
Ant control
problem in reading a file
to find the home directory in java