Java.net.UnknownHostException in file: // method

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

Any ideas why this is happening?

+3
source share
3 answers

third / is in the wrong place, url file is processed using file:///<path>

+20
source

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

+4
source

Here is my solution that really works 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;
    }
+1
source

Source: https://habr.com/ru/post/1742071/


All Articles