- 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)
- {
- e.printStackTrace();
- }
- }
- }
本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1195092,如需转载请自行联系原作者