String imgBase64 = ImageToBase64ByOnline("http://192.168.0.80:8088/img/op3.jpg");
/** * 在线图片转换成base64字符串 * * @param imgURL 图片线上路径 * @return */ public static String ImageToBase64ByOnline(String imgURL) { try { ByteArrayOutputStream data = new ByteArrayOutputStream(); try { // 创建URL URL url = new URL(imgURL); byte[] by = new byte[1024]; // 创建链接 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(5000); InputStream is = conn.getInputStream(); // 将内容读取内存中 int len = -1; while ((len = is.read(by)) != -1) { data.write(by, 0, len); } // 关闭流 is.close(); } catch (IOException e) { log.