public static File downloadFile(URL url, File output) {
        BufferedInputStream in = null;
        BufferedOutputStream bout = null;
        try {
            in = new BufferedInputStream(url.openStream());
            FileOutputStream fos = new FileOutputStream(output);
            bout = new BufferedOutputStream(fos, 1024);
            byte[] data = new byte[1024];
            int x = 0;
            while ((x = in.read(data, 0, 1024)) >= 0) {
                bout.write(data, 0, x);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (bout != null) {
                try {
                    bout.close();
                } catch (IOException ignore) {
                }
            }
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ignore) {
                }
            }
        }
        return output;
    }