Vidar Kongsli
Vidar Kongsli

Reputation: 836

java.net.UnknownHostException on file:// method

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

Any ideas for why this happens?

Upvotes: 6

Views: 20076

Answers (3)

Alessandro S.
Alessandro S.

Reputation: 1033

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;
    }

Upvotes: 1

Salandur
Salandur

Reputation: 6453

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

Upvotes: 28

Etaoin
Etaoin

Reputation: 8724

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

Upvotes: 6

Related Questions