简体   繁体   English

java教程 - 未知主机异常

[英]java tutorial - unknown host exception

I'm trying to read a URL using the tutorial : http://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html 我正在尝试使用教程阅读URL: http//docs.oracle.com/javase/tutorial/networking/urls/readingURL.html

import java.net.*;
import java.io.*;

public class URLReader {
    public static void main(String[] args) throws Exception {

        URL oracle = new URL("http://www.google.com/");
        BufferedReader in = new BufferedReader(new InputStreamReader(oracle.openStream()));
        String inputLine;

        while ((inputLine = in.readLine()) != null)
            System.out.println(inputLine);

        in.close();
    }

}

But I'm getting below exception. 但我得到的是异常。 www.google.com is a known host ? www.google.com是众所周知的主持人?

Exception in thread "main" java.net.UnknownHostException: www.google.com
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:195)
    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.www.http.HttpClient.openServer(HttpClient.java:395)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:234)
    at sun.net.www.http.HttpClient.New(HttpClient.java:307)
    at sun.net.www.http.HttpClient.New(HttpClient.java:324)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:970)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:911)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:836)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1172)
    at java.net.URL.openStream(URL.java:1010)
    at URLReader.main(URLReader.java:8)

Are you behind a proxy? 你是代理人吗? Try to set the proxy in eclipse or try 尝试在eclipse中设置代理或尝试

 java -DproxySet=true -DproxyHost=10.0.0.14 -DproxyPort=6588 JavApp

Are you running behind a proxy ? 你在代理后面跑? The article seems to suggest there is a configuration needed in that case. 文章似乎表明在这种情况下需要配置。

Alternatively, the program might hang or you might see an exception stack trace. 或者,程序可能会挂起,或者您可能会看到异常堆栈跟踪。 If either of the latter two events occurs, you may have to set the proxy host so that the program can find the Oracle server. 如果发生后两个事件中的任何一个,则可能必须设置代理主机,以便程序可以找到Oracle服务器。

我认为它的网络错误检查你的互联网连接....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM