开发者

java.net.UnknownHostException on file:// method

开发者 https://www.devze.com 2022-12-27 10:06 出处:网络
failed to open file file://D/:/dev/test_all.htmlJavaException: 开发者_StackOverflow社区java.net.UnknownHostException: D
failed to open file file://D/:/dev/test_all.html  JavaException: 开发者_StackOverflow社区java.net.UnknownHostException: D

Any ideas for why this happens?


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


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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号