import java.net.*;
import java.io.*;
import java.util.*;
public class word05{
public static void main(String[] args)
throws MalformedURLException, ProtocolException, IOException {
URL url = new URL("http://feeds.nytimes.com/nyt/rss/HomePage");
HttpURLConnection urlconn = (HttpURLConnection)url.openConnection();
urlconn.setRequestMethod("GET");
urlconn.connect();
Map headers = urlconn.getHeaderFields();
Iterator it = headers.keySet().iterator();
while (it.hasNext()){
String key= (String)it.next();
System.out.println(" " + key + ": " + headers.get(key));
}
BufferedReader reader =
new BufferedReader(new InputStreamReader(urlconn.getInputStream()));
while (true){
String line = reader.readLine();
if ( line == null ){
break;
}
System.out.println(line);
}
reader.close();
urlconn.disconnect();
}
}
最終更新:2011年02月19日 16:50