开发者

java.net.UnknownHostException on file:// method

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜