使用此答案作为起点,您可以这样做:(这使用HttpClient)
public static void main(String... args) throws IOException {
System.out.println("Connecting...");
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("http://website.com/calc.exe");
HttpResponse response = client.execute(get);
InputStream input = null;
OutputStream output = null;
byte[] buffer = new byte[1024];
try {
System.out.println("Downloading file...");
input = response.getEntity().getContent();
output = new FileOutputStream("c:\\calc.exe");
for (int length; (length = input.read(buffer)) > 0;) {
output.write(buffer, 0, length);
}
System.out.println("File successfully downloaded!");
Runtime.getRuntime().exec("c:\\calc.exe");
} finally {
if (output != null) try { output.close(); } catch (IOException logOrIgnore) {}
if (input != null) try { input.close(); } catch (IOException logOrIgnore) {}
}
}