I have a model.xml file which I have placed in a directory /home/huma/abäßö. But when I parse this file I get a MalformedURLException. Strangely, if the same file is moved to the location /home/huma, I don't get any exception. To summarize, if the xml file is in some directory that contains non-english characters, I am getting a MalformedURL exception. Is there some work-around? Can someone help me with this?
<br><br>Here is the code snippet:<br><br> final String DEF_ENC = "UTF-8"; <br> String str = new String("ab\u00e4\u00df\u00f6");<br> String newStr = null;<br> try {<br> newStr = new String(
str.getBytes(DEF_ENC), DEF_ENC);<br> str = "/home/huma/" + newStr + "/model.xml"; <br> String fileName = null;<br> fileName = new String(str.getBytes(DEF_ENC), DEF_ENC);<br> File file = new File(fileName);
<br> File parent = file.getParentFile();<br> InputStream iStream = null;<br> <br> <br> iStream = new FileInputStream(file);<br> InputSource is = new InputSource(iStream);<br>
if(parent != null)<br> { <br> is.setSystemId(parent.toURL().toString());<br> }<br> SAXBuilder saxbuilder = new SAXBuilder(true);<br> Document doc = saxbuilder.build
(is);<br> Element root = doc.getRootElement();<br> String version = root.getAttributeValue("schemaVersion");<br> System.out.println("version: " + version);<br> }
<br> catch (FileNotFoundException e1) {<br> // TODO Auto-generated catch block<br> e1.printStackTrace();<br> }<br> <br> catch (UnsupportedEncodingException e) {<br> // TODO Auto-generated catch block
<br> e.printStackTrace();<br> } catch (MalformedURLException e) {<br> // TODO Auto-generated catch block<br> e.printStackTrace();<br> } catch (JDOMException e) {<br> // TODO Auto-generated catch block
<br> e.printStackTrace();<br> } catch (IOException e) {<br> // TODO Auto-generated catch block<br> e.printStackTrace();<br> }<br> }<br><br><br>This is the exception I am getting:
<br><br>java.net.MalformedURLException: no protocol: model.dtd<br> at java.net.URL.<init>(URL.java:537)<br> at java.net.URL.<init>(URL.java:434)<br> at java.net.URL.<init>(URL.java:383)<br> at
org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)<br> at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)<br> at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source)
<br> at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)<br> at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)<br> at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument
(Unknown Source)<br> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)<br> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)<br> at org.apache.xerces.parsers.XMLParser.parse
(Unknown Source)<br> at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)<br> at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)<br> at org.jdom.input.SAXBuilder.build(SAXBuilder.java
:453)<br> at ModelTest.main(ModelTest.java:47)<br><br><br>