public void download(String f, File output) { try { System.out.println("Downloading " + f + " to " + output); URL file = new URL(f); File folder = output.getParentFile(); if (!folder.exists()) folder.mkdirs(); if (output.exists()) output.delete(); output.createNewFile(); byte[] buffer = new byte[1024]; int len; BufferedInputStream bis = new BufferedInputStream(file.openStream()); FileOutputStream fos = new FileOutputStream(output); while ((len = bis.read(buffer)) != -1) fos.write(buffer,0,len); bis.close(); fos.flush(); fos.close(); } catch (Exception e) { System.out.println("Problem downloading " + f); e.printStackTrace(); } }