Answer the question
In order to leave comments, you need to log in
How to get rid of java.net.UnknownHostException: vk.com?
There is a code
URL url = new URL("http://vk.com");
BufferedInputStream inputStream = new BufferedInputStream(url.openStream());
FileOutputStream outputStream = new FileOutputStream("pathToSave/1.html");
byte[] buffer = new byte[4096];
while (inputStream.read(buffer) > 0) {
outputStream.write(buffer);
}
inputStream.close();
outputStream.close();
D:\Clouds\Dropbox\Projects\IdeaProjects\DownloadAgent\out\artifacts\DownloadAgen
t_jar>"C:\Program Files\Java\jre7\bin\java.exe" -jar DownloadAgent.jar
Exception in thread "main" java.net.UnknownHostException: vk.com
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown
Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Sour
ce)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown So
urce)
at java.net.URL.openStream(Unknown Source)
at com.redprojects.net.downloadAgent.Main.main(Main.java:14)
Answer the question
In order to leave comments, you need to log in
I met this one on Raspbian. So I didn't understand what was going on. I had to register the desired host in /etc/hosts. Thankfully only one was needed.
If the addresses are resolved safely outside of Java, then there may be something wrong with the Java network settings . These settings are written in JAVA_HOME/jre/lib/net.properties or on the command line. You can try to play around. For example, set networkaddress.cache.ttl=0
Check on the command line:
If there are errors, it's not in the code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question