Here you can find the source of downloadFileFromWeb(URL resourceURL, String fullPath)
public static void downloadFileFromWeb(URL resourceURL, String fullPath)
//package com.java2s; // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt import java.io.BufferedInputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class Main { private static final int BUFFER_SIZE = 64 * 1024; /** fullPath,eg: "D:\\ALL_integrate_patch_v4.2.2.r63143-20110722.zip **/ public static void downloadFileFromWeb(URL resourceURL, String fullPath) { FileOutputStream fos = null; BufferedInputStream bis = null; HttpURLConnection conn = null; byte[] buf = new byte[BUFFER_SIZE]; int size = 0; File fileTostore = null;/*from w w w . j a v a2s . co m*/ try { conn = (HttpURLConnection) resourceURL.openConnection(); conn.connect(); InputStream inputStream = conn.getInputStream(); bis = new BufferedInputStream(inputStream); fileTostore = new File(fullPath); if (!fileTostore.exists()) { fileTostore.createNewFile(); } else { fileTostore.delete(); fileTostore.createNewFile(); } fos = new FileOutputStream(fullPath); while ((size = bis.read(buf)) != -1) { fos.write(buf, 0, size); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { buf = null; bis.close(); fos.close(); } catch (IOException e) { e.printStackTrace(); } conn.disconnect(); } } }