2010-01-20 14 views

उत्तर

8

ओपनस्ट्रीम() से लौटाए गए यूआरएल के इनपुटस्ट्रीम से बस एक बुफर्ड रीडर (या स्ट्रिंग को पढ़ने वाली कोई भी चीज़) संलग्न करें।

public static void main(String[] args) 
     throws IOException 
{ 
    URL url = new URL("http://stackoverflow.com/"); 
    BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); 

    String s = null; 
    while ((s = reader.readLine()) != null) 
     System.out.println(s); 
} 
0

आप सीधे जावा वर्गों का उपयोग कर सकते हैं:

URL url = new URL("http://www.example.com"); 
URLConnection conn = url.openConnection(); 
InputStream in = conn.getInputStream(); 
... 

लेकिन इसे और अधिक Apache HttpClient HttpClient के रूप में उपयोग करने के लिए चीजें आप जावा देशी वर्गों के साथ अपने आप को करना होगा कि का एक बहुत संभाल लेंगे अनुशंसा की जाती है।

संबंधित मुद्दे