将图片服务器地址转化为BASE64位字符串。
import org.apache.commons.codec.binary.Base64;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class Img2Base64Util {
/***
*
* 将图片转换为Base64<br>
* 将base64编码字符串解码成img图片
* @param imgFile
* @return
*/
public static String getImgStr(String imgFile){
ByteArrayOutputStream data = new ByteArrayOutputStream();
try {
// 创建URL
URL url = new URL(imgFile);
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