[size=large]代码例子:[/size]
package com.test;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
public class URLConnectionTest
{
public static void main(String[] args) throws Exception
{
URL url = new URL("http://www.infoq.com");
InputStream in = url.openStream();
OutputStream os = new FileOutputStream("C:/3.txt");
byte[] buffer = new byte[2048];
int length = 0;
while (-1 != (length = in.read(buffer, 0, buffer.length)))
{
//String str = new String(buffer,0,length);
// System.out.println(str);
os.write(buffer,0,length);
}
os.close();
in.close();
}
}