打开连接和读取流

时间:2013-11-21 02:06:26

标签: java exception-handling web-crawler

当我尝试执行“http://www.oracle.com”时出现运行时错误。它说,error java.net.UnknnownHostException:www.oracle.com然后它列出了一大堆与Sockets,HttpURLConnection等有关的错误。它们都指向这个连接方法,特别是InputStream steam行。

这是我的代码:

   public void connect (String website) throws IOException {

     URL u = new URL(website);
     URLConnection conn = u.openConnection();
     InputStream stream = conn.getInputStream();
     Scanner input = new Scanner(stream);
     input.useDelimiter("<a");
     readWebsite(input);

  }

1 个答案:

答案 0 :(得分:0)

尝试通过IP地址连接:

URL u = new URL("http://23.56.70.140");