Java可以使用URL类和URLConnection类来下载文件到指定目录。代码示例如下:
try {
URL url= new URL("http://example.com/example.zip");
URLConnection conn = url.openConnection();
InputStream in = conn.getInputStream();
FileOutputStream out = new FileOutputStream("C:\\example.zip");
byte[] b = new byte[1024