public class TestHTTP
{
public static void main(String[] args)
{
try
{
URL url = new URL("http://www.51cto.com/glblong.txt");
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
int length = 0;
byte[] buffer = new byte[1024];
while (-1 != (length = is.read(buffer)))
{
System.out.print(new String(buffer, 0, length));
}
}
catch (MalformedURLException e)
e.printStackTrace();
catch (IOException e)
}
}
本文轉自 glblong 51CTO部落格,原文連結:http://blog.51cto.com/glblong/1195092,如需轉載請自行聯系原作者