亲测有效,可自己试用
package com.ant.ai.xiaoheng.dataDownload.download; import java.io.File; import java.net.URL; import org.apache.commons.io.FileUtils; public class DownloadURLFiles { /** * @param args */ public static void main(String[] args) { String res = downloadFromUrl("https://pic.netbian.com/uploads/allimg/210419/203429-1618835669e1dd.jpg","D:/"); System.out.println(res); } public static String downloadFromUrl(String url,String dir) { try { URL httpurl = new URL(url); String fileName = getFileNameFromUrl(url); System.out.println(fileName); File f = new File(dir + fileName); FileUtils.copyURLToFile(httpurl, f); } catch (Exception e) { e.printStackTrace(); return "Fault!"; } return "Successful!"; } public static String getFileNameFromUrl(Stri
版权声明:本文为jjyybsm原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。