HttpUtil { public static void doGetDowloadFile(final String url, final String absolutePath) { File f = new File(absolutePath); if (!f.exists()) { Request request = new Request.Builder().url(url).build(); OkHttpClient okHttpClient = getOkHttpClient(); Call call = okHttpClient.newCall(request); try { Response response = call.execute(); IOUtil.copyFileFromInputStream(absolutePath, response.body().byteStream()); } catch (IOException e) { throw new UtilException(e); } } }  static String doGet(final String url); static String doGet(final String url, final String charset); static String doGet(final String url, final String charset, final String authorization); static String doPost(final String url, final Map<String, String> paramMap); static String doPost(final String url, final Map<String, String> paramMap, final String charset); static String getStringRequest(final Request request, final String charset); static String doPost(final String url, final String body, final String contentType, final String charset); static String doPost(final String url, final String body, final String contentType); static String doPost(final String url, final String body, final String contentType,
                                final String authorization, final String charset); static String doPost(final String url, final String body, final String contentType,
                                final Map<String, String> paramMap, final String charset); static String doPost(final String url, final String body); static void doGetDowloadFile(final String url, final String absolutePath); static String getRequestURL(final HttpServletRequest request, final boolean includeQueryString); static String getRequestURI(final HttpServletRequest request, final boolean includeQueryString); static String getRequestRelaURI(final HttpServletRequest request, final boolean includeQueryString); static String getRequestIp(final HttpServletRequest request); static String getClientInfo(final HttpServletRequest request); static boolean isAsynRequest(final HttpServletRequest request); static final int DEFAULT_HTTP_PORT; static final int DEFAULT_HTTPS_PORT; }
@Test public void doGetDowloadFile() { HttpUtil.doGetDowloadFile("https: + "&quality=80&size=b9999_10000&sec=1506669107&di=3f964616fbb30dc8e9090f3921ce6dbf" + "&imgtype=jpg&er=1&src=http%3A%2F%2Fimgsrc.baidu.com%2Fbaike%2Fpic%" + "2Fitem%2Fcb8065380cd79123ea3a4a45af345982b2b7802d.jpg", "a2.jpg"); }