本帖最后由 lishouxing 于 2011-07-22 17:34:09 编辑

解决方案 »

  1.   

    唉 现在问题升级了:
    最原始的方案:开始是可以运行的。后来出现了 这样一个错误:图片是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
    求解
      

  2.   

      URLconnection
      getInputStream  
      ImageIo.read(inputstream)