アットウィキロゴ

game0114

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

public class game0114{
    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月09日 21:30