//HttpUtils工具类下getUrlInputStream(String urlPath)方法返回输入流public static InputStream getUrlInputStream(String urlPath){
InputStream inputStream = null;
try {
URL url = new URL(urlPath);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
inputStream = connection.getInputStream();// try {
// Thread.sleep(1000);
// } catch (Exception e) {
// } } catch (Exception e) {
System.out.println(e);
}
return inputStream;
}//这是从数据库读取图片路径程序片段,从另一WEB服务器下载图片转换为字符再经JSON传送到客户端 String photoStr = null;
if (rs.getString(14) != null){
photoStr = HttpUtils.doFileStreamToString(HttpUtils.getUrlInputStream("http://10.0.0.43"+rs.getString(14)));
}
user.setMessagerurl(photoStr);问题出现在获取流那里,如果不加Thread.sleep(1000);获取图片流不完整是怎么回事?求大神解答下,小弟菜鸟~ 献丑了
Java网络
InputStream inputStream = null;
try {
URL url = new URL(urlPath);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
inputStream = connection.getInputStream();// try {
// Thread.sleep(1000);
// } catch (Exception e) {
// } } catch (Exception e) {
System.out.println(e);
}
return inputStream;
}//这是从数据库读取图片路径程序片段,从另一WEB服务器下载图片转换为字符再经JSON传送到客户端 String photoStr = null;
if (rs.getString(14) != null){
photoStr = HttpUtils.doFileStreamToString(HttpUtils.getUrlInputStream("http://10.0.0.43"+rs.getString(14)));
}
user.setMessagerurl(photoStr);问题出现在获取流那里,如果不加Thread.sleep(1000);获取图片流不完整是怎么回事?求大神解答下,小弟菜鸟~ 献丑了
Java网络
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货