All pastes #3400 Raw Edit

Downloader for swizz

public java v1 · immutable
#3400 ·published 2004-12-26 06:07 UTC
rendered paste body
      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();        }    }