Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.DataInputStream;
import java.io.FileOutputStream;
import java.net.URL;
import java.net.URLConnection;

public class Main {
    public static void main(String args[]) throws Exception {
        byte[] b = new byte[1];
        URL url = new URL("http://www.server.com/a.gif");
        URLConnection urlConnection = url.openConnection();
        urlConnection.connect();
        DataInputStream di = new DataInputStream(urlConnection.getInputStream());

        FileOutputStream fo = new FileOutputStream("a.gif");
        while (-1 != di.read(b, 0, 1))
            fo.write(b, 0, 1);
        di.close();
        fo.close();
    }
}