public static void getByUrl(URL url, String localFilename, String UA)
    throws IOException {
        // Setto gli stream
        InputStream inStream = null;
        FileOutputStream outStreamFile = null;

        try {
            // Apro la connessione con l'url datomi e setto lo user-agent come fossi browser
            URLConnection conn = url.openConnection();
            if (UA != null)
                conn.setRequestProperty("User-Agent", UA);

            // Carico il payload
            inStream = conn.getInputStream();
            outStreamFile = new FileOutputStream(localFilename);
            byte[] buffer = new byte[4096];
            int len;
            while ((len = inStream.read(buffer)) > 0) {
                outStreamFile.write(buffer, 0, len);
            } 
        // Chiudo e pulisco
        } catch(IOException e){ 
        	System.out.println("File receive error: "+e);
        }try {if (inStream != null) {inStream.close();}
        		}
        catch(IOException e){System.out.println("File receive error: "+e);
        }finally {
                if (outStreamFile != null) {
                    outStreamFile.close();
                }
            }
        }