Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.*;

import java.net.URL;

public class Main {

    public static void downLoadFile(final String strUrl, final String fileURL) {
        downLoadFile(strUrl, fileURL, 4096);
    }

    public static void downLoadFile(final String strUrl, final String fileURL, final int bufferLength) {
        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        try {

            in = new BufferedInputStream(new URL(strUrl).openStream());
            File img = new File(fileURL);
            out = new BufferedOutputStream(new FileOutputStream(img));
            byte[] buf = new byte[bufferLength];
            int count = in.read(buf);
            while (count != -1) {
                out.write(buf, 0, count);
                count = in.read(buf);
            }
            in.close();
            out.close();

        } catch (Exception e) {
            e.printStackTrace();

        }

    }
}