Here you can find the source of createBase64EncodedStringFromURL(URL url)
public static String createBase64EncodedStringFromURL(URL url) throws IOException
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import javax.xml.bind.DatatypeConverter; public class Main { public static String createBase64EncodedStringFromURL(URL url) throws IOException { final InputStream inputStream = url.openStream(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); }//from w w w. jav a 2 s . com outputStream.close(); inputStream.close(); final byte[] bytes = outputStream.toByteArray(); return "data:image/png;base64," + DatatypeConverter.printBase64Binary(bytes); } }