小程序
小游戏
企业微信
微信支付
扫描小程序码分享
获取微信头像后怎么保存到本地
3 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
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 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();
}
楼上正解