import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class UrlTest
{
public static void main(String args[]) throws IOException
{
URL url=new URL("http://www.baidu.com");
URLConnection urlconnection=url.openConnection();
InputStream is=urlconnection.getInputStream();
<span style="white-space:pre"> </span>//上面两行可以换为:InputStream is=url.openStream();<span style="white-space:pre">
</span> OutputStream os=new FileOutputStream("c:/out.html");
byte[] by=new byte[1024];
int length=0;
while(-1!=(length=is.read(by, 0,by.length)))
{
os.write(by, 0, length);
}
is.close();
os.close();
}
}