Util.java Source code

Java tutorial

Introduction

Here is the source code for Util.java

Source

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;

public class Util {

    public static void download(URL url, File to) throws IOException {
        BufferedInputStream in = new BufferedInputStream(url.openStream());
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(to));
        int bit = -1;
        while ((bit = in.read()) != -1) {
            out.write(bit);
        }
        in.close();
        out.close();
    }
}