package Run; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; class Main { public static void main(String[] args) { try { URL url = new URL("http://dl6.jnyxx.com/soft3/vim.zip"); //url描述 URLConnection con = url.openConnection(); //打开文件连接 InputStream in = con.getInputStream(); //获取网络文件的输入流 FileOutputStream fs = new FileOutputStream("d:/vim.zip"); //本地存储文件 byte[] buf = new byte[1024]; //缓冲区 int bytes = -1; while ( (bytes = in.read(buf)) != -1) { fs.write(buf, 0, bytes); //写入 } fs.close(); } catch (MalformedURLException e) { System.out.println("URL非法!"); } catch (IOException e) { System.out.println("无法打开链接!"); } } }