import java.net.*;import java.io.*;class ConnectionTest { public static void main(String[] args) { try { URL google = new URL("http://www.google.com/"); URLConnection googleConnection = google.openConnection(); DataInputStream dis = new DataInputStream(googleConnection.getInputStream()); StringBuffer inputLine = new StringBuffer(); String tmp; while ((tmp = dis.readLine()) != null) { inputLine.append(tmp); System.out.println(tmp); } //use inputLine.toString(); here it would have whole source dis.close(); } catch (MalformedURLException me) { System.out.println("MalformedURLException: " + me); } catch (IOException ioe) { System.out.println("IOException: " + ioe); } }}这就是你想要的。



