I used below code to read sub context news from bbc site,but it is throwing UnknownHostException.Any hints please.
try {
InetAddress addr = InetAddress.getByName("bbc.co.uk/news/");
int port = 80;
// This constructor will block until the connection succeeds
Socket socket = new Socket(addr, port);
} catch (UnknownHostException e) {
System.out.println("exception is"+e);
} catch (IOException e) {
}
From the JavaDoc on
InetAddress.getByName(...):In
bbc.co.uk/news/the host isbbc.co.ukwithnewsbeing a subcontext as you already stated.So change that to
InetAddress.getByName("bbc.co.uk")or alternatively use theURLclass, if you don’t have to use aSocket:new URL("http://bbc.co.uk/news/").openStream().