- 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();
- }
- }
- }