怎么获取微信头像这里就不多做介绍了!
第一种
public static void avatarUrl(String imageUrl) throws IOException {
URL url = new URL(imageUrl);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
// 得到URL的输入流
InputStream input = con.getInputStream();
// 设置数据缓冲
byte[] bs = new byte[1024 * 2];
// 读取到的数据长度
int len = 0;
// 输出的文件流保存图片至本地
OutputStream os = new FileOutputStream("E:\\avatar\\a.jpg");
while ((len = input.read(bs)) != -1) {
os.write(bs, 0, len);
}
os.close();
input.close();
}
第二种
public static String ava(String url) throws IOException {
BufferedImage bufferedImage = ImageIO.read(new URL(url));
File file = new File("E:\\avatar\\b.jpg");
ImageIO.write(bufferedImage,"jpg",file);
}