File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MalformedURLException

 
Dalia Sultana
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20176
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic