Posted
Filed under JSP, JAVA
//java save data as image from image url

public static void image_download(String turl, String fname) throws Exception{
   URL url = new URL(turl);
   InputStream in = new BufferedInputStream(url.openStream());
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   byte[] buf = new byte[1024];
   int n = 0;
   while (-1!=(n=in.read(buf)))
   {
      out.write(buf, 0, n);
   }
  
   out.close();
   in.close();
   byte[] response = out.toByteArray();
  
   FileOutputStream fos;
   fos = new FileOutputStream(fname);
   fos.write(response);
   fos.close();
 }
2015/02/12 16:36 2015/02/12 16:36