【问题标题】:How to download the response of images which comes in array?如何下载数组中图像的响应?
【发布时间】:2018-12-10 12:07:47
【问题描述】:

因为我使用 angular 5 作为前端,spring boot 作为后端...这里是下载图像响应 (JSON) 的情况...

【问题讨论】:

  • 您是否将图像保存为 blob 格式?

标签: angular spring-boot


【解决方案1】:
  try{
     String fileName = "digital_image_processing.jpg";
     String website = "http://tutorialspoint.com/java_dip/images/"+fileName;

     System.out.println("Downloading File From: " + website);

     URL url = new URL(website);
     InputStream inputStream = url.openStream();
     OutputStream outputStream = new FileOutputStream(fileName);
     byte[] buffer = new byte[2048];

     int length = 0;

     while ((length = inputStream.read(buffer)) != -1) {
        System.out.println("Buffer Read of length: " + length);
        outputStream.write(buffer, 0, length);
     }

     inputStream.close();
     outputStream.close();

  }catch(Exception e){
     System.out.println("Exception: " + e.getMessage());
  }

【讨论】:

  • 这里不欢迎发布没有任何解释的代码(并且不会帮助正在寻找解决方案的人)。你能编辑你的答案吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-19
  • 2022-01-08
  • 1970-01-01
  • 1970-01-01
  • 2018-03-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多