Url package hbfu.Url;import java.io.*;import java.io.FileOutputStream;import java.io.IOException;import javax.swing.text.html.ImageView;import okio.*;import okhttp3.*;import okhttp3.Request.Builder;public class Https {public static ImageVie
package hbfu.Url; import java.io.*; import java.io.FileOutputStream; import java.io.IOException; import javax.swing.text.html.ImageView; import okio.*; import okhttp3.*; import okhttp3.Request.Builder; public class Https { public static ImageView imageView; private final static String IMAGE_URL = "http://www.hbcf.edu.cn/wwwfile/newsimg/20171103081600020.jpg"; private static OkHttpClient client; public static void main(String[] args) throws IOException{ client = new OkHttpClient(); final Request request = new Request.Builder() .url(IMAGE_URL) .build(); client.newCall(request).enqueue(new Callback() { public void onFailure(Request request, IOException e) { e.printStackTrace(); } @Override public void onResponse(Call call, Response response) throws IOException { if (!response.isSuccessful()) { throw new IOException("服务器端错误: " + response); } System.out.println(response.body().byteStream()); byte[] bytes = (byte[]) response.body().bytes(); try{ String URL="D:/ak26.bmp";//创建本地图片URL File file=new File(URL); FileOutputStream fos=new FileOutputStream(file); fos.write(bytes,0,bytes.length); fos.flush(); fos.close(); //byte2image test = new byte2image(bytes,); //...... }catch(Exception e){ System.out.println("Exception: " + e); e.printStackTrace(); } } @Override public void onFailure(Call arg0, IOException arg1) { // TODO Auto-generated method stub } }); } private static Builder url(String imageUrl) { // TODO Auto-generated method stub return null; } }