The following code is throwing the exception below:
URL u = new URL("file://D:/abc.xml");
InputStream input = u.openStream();
Exception thrown:
Exception in thread "main" java.net.UnknownHostException: D
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.NetworkClient.openServer(NetworkClient.java:118)
at sun.net.ftp.FtpClient.openServer(FtpClient.java:488)
at sun.net.ftp.FtpClient.openServer(FtpClient.java:475)
at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:270)
at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:352)
at java.net.URL.openStream(URL.java:1010)
at com.nuance.nlu.JavaApiExmaple.main(Exmaple.java:191)
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [../../../src/share/back/util.c:820]
However if I use:
URL u = new URL("file:///D:/abc.xml");(3 slashes after file), or:URL u = new URL("file:/D:/abc.xml");(1 slash after file:)
the line of code InputStream input = u.openStream(); executes fine.
First see: What is the reason that file URLs start with three slashes: “file:///” etc? for a detailed description.
Excerpt from that answer: