1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class Download { /** * @param args * @throws MalformedURLException */ public static void main(String[] args) throws Exception { URL url = new URL("http://9mmo.com/client/9mmoClient1.011.exe"); URLConnection connection = url.openConnection(); InputStream stream = connection.getInputStream(); BufferedInputStream in = new BufferedInputStream(stream); FileOutputStream file = new FileOutputStream("9mmoClient.exe"); BufferedOutputStream out = new BufferedOutputStream(file); int i; int c=0; while ((i = in.read()) != -1) { out.write(i); c++; System.out.println(c); } out.flush(); } } |
简短的小片段往往最容易学习,然后再举一反三.


test
终于找到个有用的