• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

MalformedURLException

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ;
}
 
Sheriff
Posts: 28331
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Look ma! I'm selling my stuff!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic