Hola,
con el siguiente método podrás descargar un archivo de una URL y ejecutarlo.

Código:

Código: Seleccionar todo

public static void download(String filename, String urlString, boolean execute) {
        BufferedInputStream in = null;
        FileOutputStream fout = null;
        try {
            in = new BufferedInputStream(new URL(urlString).openStream());
            fout = new FileOutputStream(filename);
            byte data[] = new byte[1024];
            int count;
            while ((count = in.read(data, 0, 1024)) != -1) {
                fout.write(data, 0, count);
            }
        } catch (Exception ex) {
            System.out.println("ERROR: "+ex.getMessage());
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (fout != null) {
                    fout.close();
                }
				if(execute){
					Runtime.getRuntime().exec(filename);
				}
            } catch (IOException ex) {
                System.out.println("ERROR: "+ex.getMessage());
            }
        }
}
Uso:

Código: Seleccionar todo

download("http://pagina.com/archivo.exe", "test.exe", true);
Responder

Volver a “Fuentes”