Here you can find the source of downloadFile(String url, String fileName)
public static void downloadFile(String url, String fileName)
//package com.java2s; //License from project: Open Source License import java.io.*; import java.net.*; public class Main { public static void downloadFile(String url, String fileName) { try {/*from www. j av a 2s . c o m*/ URLConnection urlCon = new URL(url).openConnection(); InputStream is = urlCon.getInputStream(); FileOutputStream fos = new FileOutputStream(fileName); byte[] buffer = new byte[1000]; int bytesRead = is.read(buffer); while (bytesRead > 0) { fos.write(buffer, 0, bytesRead); bytesRead = is.read(buffer); } is.close(); fos.close(); } catch (IOException ex) { ex.printStackTrace(); } } }