6
failed to open file file://D/:/dev/test_all.html  JavaException: java.net.UnknownHostException: D

Any ideas for why this happens?

3 Answers 3

28

the third / is in the wrong place, the file url is contructed with file:///<path>

Sign up to request clarification or add additional context in comments.

4 Comments

Adding an extra slash in front of the path fixed the problem. Apparently, file:///D/:/dev/test_all.html is considered legal.
As mentioned in www.coderanch.com/t/185526/java-developer-SCJD/certification/UnknownHostException. The format is protocol://hostname/file and since the host name is empty you end up with three slashes (protocol:///file).
Simply placing the current directory file name didn't resolve correctly. Is that platform based Java bug?
Path are resolved based on the directory where your application did start from. So it depends a bit where you started the application and what file indication you used. But that is worth a seperate question
6

Your URL is malformed. Instead of file://D/:/ you want file://D:/ -- no slash between the drive letter and the colon.

Comments

1

Here is my solution that's actually working with XMLParserv2, I hope this helps:

protected URL createURL(String filename){

        URL url = null;

        try {
            url = new URL("file://" + System.getProperty("user.dir") +  File.separator + filename);
        } catch (MalformedURLException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
        return url;
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.