public static String getImageStr(String urlString){
try {
// 构造URL
URL url = new URL(urlString);
// 打开URL连接
URLConnection con = url.openConnection();
InputStream is = null;
byte[] data = null;
try {
is = con.getInputStream();
data = new byte[is.available()];
is.read(data);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
// 加密
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(data);
}catch (Exception e){
e.printStackTrace();
}
return null;
}
urlString 下载到文件流。
我需要把把流转成base64编码的字符串,就给接口调用方。他们解析出来的图片基本都是不完整的。不知道这的哪里读取除了问题。请教大神改改。万分感谢。