关于报表转成图片格式(JPG,GIF)的一个问题 本帖最后由 lishouxing 于 2011-07-22 17:34:09 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 唉 现在问题升级了:最原始的方案:开始是可以运行的。后来出现了 这样一个错误:图片是64K 但是保存下来就是5K 。而且图片不能浏览。是空的 啥都没有。一开始是能正常浏览的。 /** * 功能:把报表的图片存储到本地 * @param connPath * 连接地址 * @param saveLocalPath * 图片保存的本地地址 * @param ImgName * 图片名字 */ private void downImage(String connPath,String saveLocalPath,String ImgName){ try { //输出地址 String patAll=saveLocalPath+"//"+"JPEG"; //找不到指定位置 先创建 File file=new File(patAll); if(!file.exists()) file.mkdirs(); URL url = new URL(connPath); URLConnection con = url.openConnection(); InputStream input = con.getInputStream(); System.out.println("数据量的大小:"+input.available()); byte[] bs = new byte[1024 * 2]; int len; OutputStream os = new FileOutputStream(patAll+"//"+ImgName+".JPEG"); while ((len = input.read(bs)) != -1) { System.out.println(bs); os.write(bs,0,len); } os.close(); input.close(); } catch (Exception e) { e.printStackTrace(); }finally{ } }现在解决方案是这样的://报表图片存储至本地 private void imageSaveLocal(String connPath,String saveLocalPath,String ImgName){ String patAll=saveLocalPath+"//"+"JPEG"; try { File imageFile=new File(connPath); BufferedImage bi=ImageIO.read(imageFile); File imageOutputFile=new File(patAll+"//"+ImgName+".jpg"); ImageIO.write(bi,"jpg",imageOutputFile); } catch (IOException e) { System.out.println("... read image exception"); e.printStackTrace(); } }但是报的错误是:javax.imageio.IIOException: Can't read input file!写到输入流的地址是:https://pc2011061310iox:8443/DIET/reportServlet?action=9&graphId=100001&time=1313549659828求解 URLconnection getInputStream ImageIo.read(inputstream) SSH框架中懒加载问题 在线等!!!!求大神 SSH2分页 页面得不到值 求助:计算一个超长字符串中的子串个数 win7 ie8 正常请求应用几次后,再次请求会出现一直处于正在加载的状态,过一会儿浏览器显示无法连接 tomcat 安装问题? 请问,为什么要使用商用的服务器,用tomcat+jboss,缺点在哪里? 如何实现手机短信发送??? java日期问题 如何使用sql来对CSV操作 基于Druid连接池的JdbcTemplate.queryForObject 一直返回空对象 求解释 一个小问题求解
最原始的方案:开始是可以运行的。后来出现了 这样一个错误:图片是64K 但是保存下来就是5K 。而且图片不能浏览。是空的 啥都没有。一开始是能正常浏览的。
/**
* 功能:把报表的图片存储到本地
* @param connPath
* 连接地址
* @param saveLocalPath
* 图片保存的本地地址
* @param ImgName
* 图片名字
*/
private void downImage(String connPath,String saveLocalPath,String ImgName){
try { //输出地址
String patAll=saveLocalPath+"//"+"JPEG";
//找不到指定位置 先创建
File file=new File(patAll);
if(!file.exists())
file.mkdirs();
URL url = new URL(connPath);
URLConnection con = url.openConnection();
InputStream input = con.getInputStream();
System.out.println("数据量的大小:"+input.available()); byte[] bs = new byte[1024 * 2];
int len;
OutputStream os = new FileOutputStream(patAll+"//"+ImgName+".JPEG");
while ((len = input.read(bs)) != -1) {
System.out.println(bs);
os.write(bs,0,len);
}
os.close();
input.close();
} catch (Exception e) {
e.printStackTrace();
}finally{
}
}现在解决方案是这样的:
//报表图片存储至本地
private void imageSaveLocal(String connPath,String saveLocalPath,String ImgName){
String patAll=saveLocalPath+"//"+"JPEG";
try {
File imageFile=new File(connPath);
BufferedImage bi=ImageIO.read(imageFile);
File imageOutputFile=new File(patAll+"//"+ImgName+".jpg");
ImageIO.write(bi,"jpg",imageOutputFile);
} catch (IOException e) {
System.out.println("... read image exception");
e.printStackTrace();
}
}
但是报的错误是:
javax.imageio.IIOException: Can't read input file!
写到输入流的地址是:
https://pc2011061310iox:8443/DIET/reportServlet?action=9&graphId=100001&time=1313549659828
求解
getInputStream
ImageIo.read(inputstream)