MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

/*
 * Output:
 *  
 */

import java.io.InputStream;
import java.net.URL;

public class MainClass {

    public static void main(String args[]) {
        try {

            URL url = new URL("http://www.java2s.com");

            // Obtain output stream
            InputStream is = url.openStream();

            // Read and display data from url
            byte buffer[] = new byte[1024];
            int i;
            while ((i = is.read(buffer)) != -1) {
                System.out.write(buffer, 0, i);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}