first commit1

This commit is contained in:
lijiazhuo
2025-09-26 10:15:29 +08:00
parent 024c4bc562
commit f3ffb8a795

View File

@ -0,0 +1,31 @@
package com.example.sso.test;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
public class D {
public static void main(String[] args) {
try {
String imageUrl = "https://cc-kf-cos-tx.7moor-fs2.com/T00000001849/m7-business/2025-05-16/1747366015733/9e1bc250-3205-11f0-bef4-1bcbfb78473d/OIP-C.jpg"; // 替换为目标图片URL
String substring = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
String savePath = "D:\\下载模板\\"+substring; // 本地保存路径
URL url = new URL(imageUrl);
InputStream in = url.openStream();
FileOutputStream out = new FileOutputStream(savePath);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
in.close();
out.close();
System.out.println("图片下载成功!");
} catch (Exception e) {
e.printStackTrace();
}
}
}