2010-05-26 60 views
2

在执行以下代码:MalformedURLException的使用文件URI

 doc = builder.parse(file); 

其中docorg.w3c.dom.Documentbuilder一个实例是javax.xml.parsers.DocumentBuilder一个实例,我发现了以下异常:

Exception in thread "main" java.net.MalformedURLException: unknown protocol: c 
     at java.net.URL.<init>(Unknown Source) 
     at java.net.URL.<init>(Unknown Source) 
     at java.net.URL.<init>(Unknown Source) 
     at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source) 
     at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(Unknown Source) 
     at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(Unknown Source) 
     at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(Unknown Source) 
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(Unknown Source) 
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(Unknown Source) 
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source) 
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) 
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) 
     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) 
     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) 
     at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) 
     at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) 
     at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source) 
     at javax.xml.parsers.DocumentBuilder.parse(Unknown Source) 
     at com.acme.ItemToThetaValues.createFiles(ItemToThetaValues.java:47) 

它在文件的这一行上窒息:

<!DOCTYPE questestinterop SYSTEM "C:\Program Files\Acme\parsers\acme_full.dtd"> 

我的机器上没有出现此错误,而用户正在使用他的机器。我们都使用Sun JRE的第6版。当他在路径中使用双反斜杠而不是单反斜杠时,以及使用正斜杠而不是反斜杠时,也会发生此错误。

首先,XML是否正确?路径表达是否正确?其次,为什么这个错误发生在一台电脑上,而不是另一台电脑上?

回答